diff --git a/src/routes/auth.js b/src/routes/auth.js index 4a70ae7..2f0da93 100644 --- a/src/routes/auth.js +++ b/src/routes/auth.js @@ -15,15 +15,15 @@ import { createCustomer } from '../utils/stripe.js'; * @param {() => void} done */ export const authRoutes = (fastify, _, done) => { - fastify.get("/google/callback", async (request, response) => { + fastify.get("/google/callback", async (request, reply) => { let token = ""; try { /** @type {{token: import('@fastify/oauth2').Token}} */ - const response = await fastify.googleOAuth2.getAccessTokenFromAuthorizationCodeFlow(request); - token = response.token; + const token_response = await fastify.googleOAuth2.getAccessTokenFromAuthorizationCodeFlow(request); + token = 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" }); + reply.status(400).send({ success: false, message: "Provider email is not verified" }); return; } const channel_info = await getChannelInfo(token.access_token); @@ -64,7 +64,7 @@ export const authRoutes = (fastify, _, done) => { if (user.length == 0) { - response.status(400).send({ success: false, message: "Problem when creating user account" }); + reply.status(400).send({ success: false, message: "Problem when creating user account" }); return; } } @@ -82,7 +82,7 @@ export const authRoutes = (fastify, _, done) => { else { let session_info = await tx.select().from(users).leftJoin(sessions, eq(sessions.user_id, users.id)).where(eq(users.google_id, user_info.id)); if (!session_info || session_info.length == 0) { - response.status(400).send({ success: false, message: "Problem when creating user account" }); + reply.status(400).send({ success: false, message: "Problem when creating user account" }); await tx.rollback(); return; } @@ -104,7 +104,7 @@ export const authRoutes = (fastify, _, done) => { // domain: ".omersabic.com" // }).redirect(env.FRONTEND_URL); - response.redirect(env.FRONTEND_URL + "/auth?token=" + session_id); + reply.redirect(env.FRONTEND_URL + "/auth?token=" + session_id); // response.send({ // token: session_id @@ -112,11 +112,11 @@ export const authRoutes = (fastify, _, done) => { return; } catch (e) { if(e.message === "no_channel") { - response.status(400).send("Your account does not have a youtube channel. Please make one.") + reply.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." }); + reply.send({ success: false, message: "There was a problem when making your account." }); return; } });