From a9cc728ade1f9a037b1d9b01fa247873b8523158 Mon Sep 17 00:00:00 2001 From: Hafid Nur Date: Thu, 3 Apr 2025 06:10:07 +0700 Subject: [PATCH] feat(backoffice): implement login and logout - Tambah fitur login dan logout pada Backoffice - Ubah port development server dan atasi CORS - Update type login response - Update component Input agar toggle password berfungsi dengan benar --- apps/backoffice/src/app/page.tsx | 5 +++++ apps/backoffice/vite.config.ts | 4 ++-- libs/service/src/types/auth/index.ts | 18 ++++++++++++++++++ libs/ui/src/atoms/input/input.tsx | 4 +++- .../backoffice-sidebar/backoffice-sidebar.tsx | 11 ++++++++--- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/apps/backoffice/src/app/page.tsx b/apps/backoffice/src/app/page.tsx index 7ba7fee..dc8a0c8 100644 --- a/apps/backoffice/src/app/page.tsx +++ b/apps/backoffice/src/app/page.tsx @@ -16,6 +16,10 @@ export const Components: FC = (): ReactElement => { console.log(payload); // for debugging const response = await postLogin(payload); + const { access_token, refresh_token } = response.data.token; + sessionStorage.setItem('access_token', access_token); + localStorage.setItem('refresh_token', refresh_token); + console.log('Login successful:', response); // for debugging navigate('/dashboard'); } catch (error) { @@ -39,6 +43,7 @@ export const Components: FC = (): ReactElement => { className="w-full" value={email} onChange={(e) => setEmail(e.target.value)} + autoFocus /> ({ root: __dirname, cacheDir: '../../node_modules/.vite/apps/backoffice', server: { - port: 4200, + port: 3000, host: 'localhost', }, preview: { - port: 4300, + port: 3001, host: 'localhost', }, plugins: [react(), nxViteTsPaths(), nxCopyAssetsPlugin(['*.md'])], diff --git a/libs/service/src/types/auth/index.ts b/libs/service/src/types/auth/index.ts index bf094ec..03fc5a7 100644 --- a/libs/service/src/types/auth/index.ts +++ b/libs/service/src/types/auth/index.ts @@ -10,9 +10,27 @@ export type TLoginResponse = { refresh_token: string; }; user: { + role: { + id: string; + name: string; + permission: [ + { + id: string; + name: string; + created_at: string; + updated_at: string; + } + ] + created_at: string; + updated_at: string; + }; fullname: string; email: string; + avatar: string; + phone_number: string; is_active: boolean; + gender: string; + birthdate: string; }; }; }; diff --git a/libs/ui/src/atoms/input/input.tsx b/libs/ui/src/atoms/input/input.tsx index ae0e849..e780059 100644 --- a/libs/ui/src/atoms/input/input.tsx +++ b/libs/ui/src/atoms/input/input.tsx @@ -40,7 +40,8 @@ export const Input: FC = ({ }): ReactElement => { const [showPassword, setShowPassword] = useState(false); // State for password visibility - const togglePasswordVisibility = () => { + const togglePasswordVisibility = (e: React.FormEvent) => { + e.preventDefault(); if (!disabled) setShowPassword((prev) => !prev); }; @@ -63,6 +64,7 @@ export const Input: FC = ({ {type === 'password' && (