This commit is contained in:
2025-05-14 16:52:25 -05:00
parent c5eed77822
commit 2054bc86ee
3 changed files with 55 additions and 47 deletions

View File

@ -7,6 +7,7 @@ import { headers } from 'next/headers';
import { redirect } from 'next/navigation';
export const signUp = async (formData: FormData) => {
const name = formData.get('name') as string;
const email = formData.get('email') as string;
const password = formData.get('password') as string;
const supabase = await createServerClient();
@ -20,27 +21,37 @@ export const signUp = async (formData: FormData) => {
);
}
const { error } = await supabase.auth.signUp({
const { data, error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${origin}/auth/callback`,
},
//options: {
//emailRedirectTo: `${origin}/auth/callback`,
//},
});
if (error) {
console.error(error.code + ': ' + error.message);
return encodedRedirect(
'error',
'/sign-up',
'Thanks for signing up! Please check your email for a verification link.',
);
return redirect('/protected');
//return encodedRedirect('error', '/sign-up',
//'Thanks for signing up! Please check your email for a verification link.');
} else {
return encodedRedirect(
'success',
'/sign-up',
'Thanks for signing up! Please check your email for a verification link.',
);
try {
if (!data.user) throw new Error('Could not sign up');
const { error } = await supabase
.from('profiles')
.update({
full_name: name,
provider: 'email',
})
.eq('id', data.user.id);
if (error) throw new Error('Could not update profile');
} catch (error) {
console.error('Error updating profile: ', error);
} finally {
return redirect('/protected');
//return encodedRedirect('success', '/protected',
//'Thanks for signing up! Please check your email for a verification link.);
}
}
};