fixed problem with id not saving in cookies when creating an account
This commit is contained in:
parent
12835a26c6
commit
e09f30bff3
2 changed files with 13 additions and 9 deletions
|
@ -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 }
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue