fix logout

This commit is contained in:
Omer Sabic 2024-06-11 18:36:10 +02:00
parent edc3822936
commit 7f72636af2

View File

@ -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"
});