Skip to content

Commit

Permalink
fix: infinite redirect when logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Mar 13, 2023
1 parent 6773d9d commit 757f77f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/routes/auth/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module.exports.get = () => ({
access_token: accessToken,
expires_in: expiresIn,
} = await this.discord.getAccessTokenFromAuthorizationCodeFlow(req);
const redirect = this.states.get(req.query.state) || '/';
this.states.delete(req.query.state);
const user = await (await fetch('https://discordapp.com/api/users/@me', { headers: { 'Authorization': `Bearer ${accessToken}` } })).json();
const token = this.jwt.sign({
accessToken,
Expand All @@ -16,16 +18,14 @@ module.exports.get = () => ({
locale: user.locale,
username: user.username,
});
res
.setCookie('token', token, {
domain,
httpOnly: true,
maxAge: expiresIn,
path: '/',
sameSite: true,
secure: false,
})
.redirect(this.states.get(req.query.state) || '/');
this.states.delete(req.query.state);
res.setCookie('token', token, {
domain,
httpOnly: true,
maxAge: expiresIn,
path: '/',
sameSite: 'Lax',
secure: false,
});
return res.redirect(303, redirect);
},
});

0 comments on commit 757f77f

Please sign in to comment.