fixed problem with id not saving in cookies when creating an account

This commit is contained in:
Nabil Ould Hamou 2024-12-09 16:08:15 +01:00
parent 12835a26c6
commit e09f30bff3
2 changed files with 13 additions and 9 deletions

View file

@ -4,16 +4,20 @@ export async function load({ locals, url, fetch }) {
const token = locals.token;
if (token == undefined && url.pathname !== "/") {
redirect(301, "/");
redirect(301, '/');
}
let user = null;
if (locals.userId !== undefined) {
const res = await fetch(`/api/users/${locals.userId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const user = await res.json();
user = await res.json();
}
return { token, user }

View file

@ -44,7 +44,7 @@ export async function POST({request}) {
// @ts-ignore
const token = jwt.sign(newUser, process.env.JWT_SECRET, { expiresIn: "1h" });
logger.debug(`Generated a JWT token for user ${newUser.email}.`)
return json({token: token});
return json({token: token, userId: newUser.id});
} catch (e) {
logger.error(e);