AlanK
07/19/2022, 5:46 AMNeedle
07/19/2022, 5:46 AMsilentworks
07/19/2022, 1:56 PMAlanK
07/19/2022, 10:20 PMAlanK
07/19/2022, 10:20 PM<form action="/auth/signup" method="post">AlanK
07/19/2022, 10:20 PMimport { supabaseClient } from '$lib/dbClient';
export async function POST({ request }) {
const data = await request.formData();
const email = data.get('email');
const password = data.get('password');
const headers = { location: '../survey' };
const errors = {};
const values = { email, password };
const { user, error } = await supabaseClient.auth.signUp(
{
email: email,
password: password
},
{ redirectTo: '../survey' }
);
if (error) {
errors.form = error.message;
return {
status: 400,
body: {
errors,
values
}
};
}
const response = await fetch('http://127.0.0.1:5173/api/auth/callback', {
method: 'POST',
headers: new Headers({ 'Content-Type': 'application/json' }),
credentials: 'same-origin',
body: JSON.stringify({ event: 'SIGNED_UP', user })
});
return {
status: 303,
headers
};
}AlanK
07/19/2022, 10:21 PMsilentworks
07/19/2022, 10:23 PMsilentworks
07/19/2022, 10:29 PMSIGNED_UP event that gets caught in the callback handler
js
const response = await fetch('http://127.0.0.1:5173/api/auth/callback', {
method: 'POST',
headers: new Headers({ 'Content-Type': 'application/json' }),
credentials: 'same-origin',
body: JSON.stringify({ event: 'SIGNED_UP', user })
});
Do note I only use that hack on signing in on the server side in the email and password example.AlanK
07/19/2022, 10:56 PMAlanK
07/20/2022, 1:57 AMNeedle
07/20/2022, 1:57 AM