signin: async ({ request, cookies }) => {
let form = await request.formData();
let email = form.get('email') as string;
let password = form.get('password') as string;
try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});
function getCookieValue(cookieString: string) {
const match = cookieString.match(/better-auth\.session_token=([^;]+)/);
return match ? decodeURIComponent(match[1]) : '';
}
cookies.set('better-auth.session_token', getCookieValue(res.headers.getSetCookie()[0]), {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} catch (err) {
if (err instanceof APIError) {
return fail(400, { errMessage: err.body.message as string });
}
}
redirect(303, '/profile');
}
signin: async ({ request, cookies }) => {
let form = await request.formData();
let email = form.get('email') as string;
let password = form.get('password') as string;
try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});
function getCookieValue(cookieString: string) {
const match = cookieString.match(/better-auth\.session_token=([^;]+)/);
return match ? decodeURIComponent(match[1]) : '';
}
cookies.set('better-auth.session_token', getCookieValue(res.headers.getSetCookie()[0]), {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} catch (err) {
if (err instanceof APIError) {
return fail(400, { errMessage: err.body.message as string });
}
}
redirect(303, '/profile');
}