From 774ed7b4a3573ed88a82e18769646b79284b88cb Mon Sep 17 00:00:00 2001 From: Ziqi Wang Date: Sun, 8 Dec 2024 00:11:00 +0200 Subject: [PATCH] fix: discard email-verification notification. Users now can be prompt to repo page after register --- app/authentication/actions.ts | 9 +++++---- app/authentication/register/page.tsx | 17 ++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/authentication/actions.ts b/app/authentication/actions.ts index cbc0fea..6457d9a 100644 --- a/app/authentication/actions.ts +++ b/app/authentication/actions.ts @@ -30,20 +30,21 @@ export async function emailSignup(formData: FormData) { // type-casting here for convenience // in practice, you should validate your inputs - const data = { + const credentials = { email: formData.get('email') as string, password: formData.get('password') as string, } - const { error } = await supabase.auth.signUp(data) + const { data, error } = await supabase.auth.signUp(credentials) if (error) { - return { success: false, message: error.message } + return { success: false, message: error.message, data: null } } return { success: true, - message: 'Please check your email to confirm your signup.', + message: 'User has successfully signed up.', + data: data, } } diff --git a/app/authentication/register/page.tsx b/app/authentication/register/page.tsx index 66fad2e..97cfca2 100644 --- a/app/authentication/register/page.tsx +++ b/app/authentication/register/page.tsx @@ -7,6 +7,7 @@ import { emailSignup } from '../actions' import { Button } from '@/components/ui/button' import { useRouter } from 'next/navigation' import { toast } from 'sonner' +import { User } from '@supabase/supabase-js' export default function RegisterPage() { const [email, setEmail] = useState('') @@ -18,21 +19,23 @@ export default function RegisterPage() { } async function handleSignup(event: FormData) { const response = await emailSignup(event) - console.log(response) - const email = event.get('email') as string - const emailDomain = email.split('@')[1] - if (response.success) { + console.log(response.data) + // const email = event.get('email') as string + // const emailDomain = email.split('@')[1] + + if (response.success && response.data) { + const user: User | null = response.data.user toast(response.message, { action: { - label: 'GO', - onClick: () => - window.open(`https://${emailDomain}`, '_blank'), + label: 'Personal Page', + onClick: () => router.push(`/user/${user?.id}`), }, }) } else { toast.error(response.message) } + console.log(`${location.origin}/user/${123}`) } return (