fix: infinite redirect when logging in

by setting `Same-Site=Lax`: https://bugs.chromium.org/p/chromium/issues/detail?id=696204#c41
This commit is contained in:
Isaac 2023-03-13 17:04:42 +00:00
parent 6773d9ddbe
commit 757f77fb1d
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -6,6 +6,8 @@ module.exports.get = () => ({
access_token: accessToken, access_token: accessToken,
expires_in: expiresIn, expires_in: expiresIn,
} = await this.discord.getAccessTokenFromAuthorizationCodeFlow(req); } = 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 user = await (await fetch('https://discordapp.com/api/users/@me', { headers: { 'Authorization': `Bearer ${accessToken}` } })).json();
const token = this.jwt.sign({ const token = this.jwt.sign({
accessToken, accessToken,
@ -16,16 +18,14 @@ module.exports.get = () => ({
locale: user.locale, locale: user.locale,
username: user.username, username: user.username,
}); });
res res.setCookie('token', token, {
.setCookie('token', token, {
domain, domain,
httpOnly: true, httpOnly: true,
maxAge: expiresIn, maxAge: expiresIn,
path: '/', path: '/',
sameSite: true, sameSite: 'Lax',
secure: false, secure: false,
}) });
.redirect(this.states.get(req.query.state) || '/'); return res.redirect(303, redirect);
this.states.delete(req.query.state);
}, },
}); });