From 7f72636af22f6e341b1ee28926ff32692e3751df Mon Sep 17 00:00:00 2001 From: Omer Sabic Date: Tue, 11 Jun 2024 18:36:10 +0200 Subject: [PATCH] fix logout --- src/routes/auth.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/routes/auth.js b/src/routes/auth.js index b0934a6..945d303 100644 --- a/src/routes/auth.js +++ b/src/routes/auth.js @@ -16,10 +16,11 @@ import { createCustomer } from '../utils/stripe.js'; */ export const authRoutes = (fastify, _, done) => { fastify.get("/google/callback", async (request, response) => { + let token = ""; try { /** @type {{token: import('@fastify/oauth2').Token}} */ - const { token } = await fastify.googleOAuth2.getAccessTokenFromAuthorizationCodeFlow(request); - + const response = await fastify.googleOAuth2.getAccessTokenFromAuthorizationCodeFlow(request); + token = response.token; const user_info = await getUserInfo(token.access_token); if (!user_info.verified_email) { response.status(400).send({ success: false, message: "Provider email is not verified" }); @@ -113,6 +114,7 @@ export const authRoutes = (fastify, _, done) => { if(e.message === "no_channel") { response.status(400).send("Your account does not have a youtube channel. Please make one.") } + fastify.googleOAuth2.revokeToken(token, "refresh_token"); console.log(e); response.send({ success: false, message: "There was a problem when making your account." }); return; @@ -123,6 +125,7 @@ export const authRoutes = (fastify, _, done) => { preValidation: authMiddlewareFn }, async (req, reply) => { try { + await db.delete(sessions).where(eq(sessions.id, req.session.id)); await fastify.googleOAuth2.revokeToken(req.session, "refresh_token", { "content-type": "application/json" });