From 9a8fd1c073800f694fa5d15be6a6906d8af4a852 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sun, 11 May 2025 07:54:23 +0800 Subject: [PATCH] update auth guard and sign-in forms, add guidelines for custom auth to handle login and logout, --- .../cms/src/components/auth/auth-guard.tsx | 1 + .../src/components/auth/custom/_GUIDELINES.md | 10 ++ .../components/auth/custom/sign-in-form.tsx | 102 +++++++++++++++--- .../components/auth/supabase/sign-in-form.tsx | 51 +++++++-- 4 files changed, 139 insertions(+), 25 deletions(-) create mode 100644 002_source/cms/src/components/auth/custom/_GUIDELINES.md diff --git a/002_source/cms/src/components/auth/auth-guard.tsx b/002_source/cms/src/components/auth/auth-guard.tsx index 30b6e17..e79943f 100644 --- a/002_source/cms/src/components/auth/auth-guard.tsx +++ b/002_source/cms/src/components/auth/auth-guard.tsx @@ -29,6 +29,7 @@ export function AuthGuard({ children }: AuthGuardProps): React.JSX.Element | nul return; } + // NOTE: here state that if user = null, eject user to login page if (!user) { logger.debug('[AuthGuard]: User is not logged in, redirecting to sign in'); diff --git a/002_source/cms/src/components/auth/custom/_GUIDELINES.md b/002_source/cms/src/components/auth/custom/_GUIDELINES.md new file mode 100644 index 0000000..121f70b --- /dev/null +++ b/002_source/cms/src/components/auth/custom/_GUIDELINES.md @@ -0,0 +1,10 @@ +# GUIDELINES + +This folder contains login pages + +the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src` + +## Assumption and Requirements + +- assume `pb` is located in `@/lib/pb` +- no need to handle error in this function, i'll handle it in the caller diff --git a/002_source/cms/src/components/auth/custom/sign-in-form.tsx b/002_source/cms/src/components/auth/custom/sign-in-form.tsx index 8a8ea0b..5ab6b8b 100644 --- a/002_source/cms/src/components/auth/custom/sign-in-form.tsx +++ b/002_source/cms/src/components/auth/custom/sign-in-form.tsx @@ -1,4 +1,6 @@ 'use client'; +// RULES: +// refer to ticket REQ0016 for login flow import * as React from 'react'; import RouterLink from 'next/link'; @@ -25,6 +27,7 @@ import { authClient } from '@/lib/auth/custom/client'; import { useUser } from '@/hooks/use-user'; import { DynamicLogo } from '@/components/core/logo'; import { toast } from '@/components/core/toaster'; +import { pb } from '@/lib/pb'; interface OAuthProvider { id: 'google' | 'discord'; @@ -44,7 +47,7 @@ const schema = zod.object({ type Values = zod.infer; -const defaultValues = { email: '', password: '' } satisfies Values; +const defaultValues = { email: 'admin@123.com', password: 'admin@123.com' } satisfies Values; export function SignInForm(): React.JSX.Element { const router = useRouter(); @@ -103,15 +106,31 @@ export function SignInForm(): React.JSX.Element { return (
- - + +
Sign in - + Don't have an account?{' '} - + Sign up @@ -123,7 +142,15 @@ export function SignInForm(): React.JSX.Element {
- + Forgot password?
- Use{' '} - - sofia@devias.io - {' '} - with password{' '} - - Secret1 - + + + user:{' '} + + admin@123.com + {' '} + password{' '} + + admin@123.com + + + + user{' '} + + sofia@devias.io + {' '} + password{' '} + + Secret1 + + + ); diff --git a/002_source/cms/src/components/auth/supabase/sign-in-form.tsx b/002_source/cms/src/components/auth/supabase/sign-in-form.tsx index 91eba0f..3411a14 100644 --- a/002_source/cms/src/components/auth/supabase/sign-in-form.tsx +++ b/002_source/cms/src/components/auth/supabase/sign-in-form.tsx @@ -115,15 +115,31 @@ export function SignInForm(): React.JSX.Element { return (
- - + +
Sign in - + Don't have an account?{' '} - + Sign up @@ -135,7 +151,15 @@ export function SignInForm(): React.JSX.Element {
- + Forgot password?