-
-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed logout Fixed users can't logout * Update logout.js * Fix ESLint
- Loading branch information
Showing
1 changed file
with
13 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
const { domain } = require('../../lib/http'); | ||
|
||
module.exports.get = fastify => ({ | ||
handler: async function (req, res) { | ||
const { accessToken } = req.user; | ||
|
||
await fetch('https://discord.com/api/oauth2/token/revoke', { | ||
body: new URLSearchParams({ token: req.user.accessToken }).toString(), | ||
body: new URLSearchParams({ token: accessToken }).toString(), | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
method: 'POST', | ||
}); | ||
res | ||
.clearCookie('token', '/') | ||
.send('The token has been revoked.'); | ||
|
||
res.clearCookie('token', { | ||
domain, | ||
httpOnly: true, | ||
path: '/', | ||
sameSite: 'Lax', | ||
secure: false, | ||
}).send('The token has been revoked.'); | ||
}, | ||
onRequest: [fastify.authenticate], | ||
}); |