default: async ({ request, cookies }) => {
let body = await request.formData()
let email = body.get('email') as string
let password = body.get('password') as string
try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});
const setCookieHeader = res.headers.get('set-cookie');
if (setCookieHeader) {
const valueIndex = setCookieHeader.indexOf('=');
const semicolonIndex = setCookieHeader.indexOf(';');
const encodedValue = setCookieHeader.slice(
valueIndex + 1,
semicolonIndex > -1 ? semicolonIndex : undefined
);
const decodedValue = decodeURIComponent(encodedValue);
cookies.set('better-auth.session_token', decodedValue, {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} else {
return fail(500, { internalServerError: "Something went wrong while signing in" })
}
}catch(){
//other code
}
}
default: async ({ request, cookies }) => {
let body = await request.formData()
let email = body.get('email') as string
let password = body.get('password') as string
try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});
const setCookieHeader = res.headers.get('set-cookie');
if (setCookieHeader) {
const valueIndex = setCookieHeader.indexOf('=');
const semicolonIndex = setCookieHeader.indexOf(';');
const encodedValue = setCookieHeader.slice(
valueIndex + 1,
semicolonIndex > -1 ? semicolonIndex : undefined
);
const decodedValue = decodeURIComponent(encodedValue);
cookies.set('better-auth.session_token', decodedValue, {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} else {
return fail(500, { internalServerError: "Something went wrong while signing in" })
}
}catch(){
//other code
}
}