46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
'use server'
|
|
|
|
import { revalidatePath } from 'next/cache'
|
|
import { redirect } from 'next/navigation'
|
|
|
|
import { createClient } from '@/utils/supabase/server'
|
|
|
|
export async function login(formData: FormData) {
|
|
const supabase = await createClient()
|
|
|
|
const email = formData.get('email') as string
|
|
const password = formData.get('password') as string
|
|
|
|
const { error } = await supabase.auth.signInWithPassword({
|
|
email,
|
|
password,
|
|
})
|
|
|
|
if (error) {
|
|
redirect('/login?error=Could not authenticate user')
|
|
}
|
|
|
|
revalidatePath('/', 'layout')
|
|
await supabase.rpc('reactivate_profile')
|
|
redirect('/app')
|
|
}
|
|
|
|
export async function signup(formData: FormData) {
|
|
const supabase = await createClient()
|
|
|
|
const email = formData.get('email') as string
|
|
const password = formData.get('password') as string
|
|
|
|
const { error } = await supabase.auth.signUp({
|
|
email,
|
|
password,
|
|
})
|
|
|
|
if (error) {
|
|
redirect('/login?error=Could not authenticate user')
|
|
}
|
|
|
|
revalidatePath('/', 'layout')
|
|
redirect('/app')
|
|
}
|