feat: implement internal auth user creation and update related functionalities
This commit is contained in:
+17
-4
@@ -4,6 +4,7 @@ import { revalidatePath } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { getFirstAdminSetupState } from '@/lib/auth/first-admin-setup'
|
||||
import { createInternalAuthUser } from '@/lib/auth/internal-users'
|
||||
|
||||
export async function login(formData: FormData) {
|
||||
const supabase = await createClient()
|
||||
@@ -38,17 +39,29 @@ export async function signup(formData: FormData) {
|
||||
)
|
||||
}
|
||||
|
||||
const supabase = await createClient()
|
||||
|
||||
const data = {
|
||||
email: formData.get('email') as string,
|
||||
password: formData.get('password') as string,
|
||||
}
|
||||
|
||||
const { error } = await supabase.auth.signUp(data)
|
||||
try {
|
||||
await createInternalAuthUser({
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
role: 'freelancer',
|
||||
reason: 'first_admin',
|
||||
})
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : 'Kullanıcı oluşturulamadı.'
|
||||
redirect(`/register?error=true&message=${encodeURIComponent(message)}`)
|
||||
}
|
||||
|
||||
const supabase = await createClient()
|
||||
const { error } = await supabase.auth.signInWithPassword(data)
|
||||
|
||||
if (error) {
|
||||
redirect(`/register?error=true&message=${encodeURIComponent(error.message)}`)
|
||||
redirect(`/login?error=true&message=${encodeURIComponent(error.message)}`)
|
||||
}
|
||||
|
||||
revalidatePath('/', 'layout')
|
||||
|
||||
Reference in New Issue
Block a user