fix logout
This commit is contained in:
parent
edc3822936
commit
7f72636af2
@ -16,10 +16,11 @@ import { createCustomer } from '../utils/stripe.js';
|
|||||||
*/
|
*/
|
||||||
export const authRoutes = (fastify, _, done) => {
|
export const authRoutes = (fastify, _, done) => {
|
||||||
fastify.get("/google/callback", async (request, response) => {
|
fastify.get("/google/callback", async (request, response) => {
|
||||||
|
let token = "";
|
||||||
try {
|
try {
|
||||||
/** @type {{token: import('@fastify/oauth2').Token}} */
|
/** @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);
|
const user_info = await getUserInfo(token.access_token);
|
||||||
if (!user_info.verified_email) {
|
if (!user_info.verified_email) {
|
||||||
response.status(400).send({ success: false, message: "Provider email is not verified" });
|
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") {
|
if(e.message === "no_channel") {
|
||||||
response.status(400).send("Your account does not have a youtube channel. Please make one.")
|
response.status(400).send("Your account does not have a youtube channel. Please make one.")
|
||||||
}
|
}
|
||||||
|
fastify.googleOAuth2.revokeToken(token, "refresh_token");
|
||||||
console.log(e);
|
console.log(e);
|
||||||
response.send({ success: false, message: "There was a problem when making your account." });
|
response.send({ success: false, message: "There was a problem when making your account." });
|
||||||
return;
|
return;
|
||||||
@ -123,6 +125,7 @@ export const authRoutes = (fastify, _, done) => {
|
|||||||
preValidation: authMiddlewareFn
|
preValidation: authMiddlewareFn
|
||||||
}, async (req, reply) => {
|
}, async (req, reply) => {
|
||||||
try {
|
try {
|
||||||
|
await db.delete(sessions).where(eq(sessions.id, req.session.id));
|
||||||
await fastify.googleOAuth2.revokeToken(req.session, "refresh_token", {
|
await fastify.googleOAuth2.revokeToken(req.session, "refresh_token", {
|
||||||
"content-type": "application/json"
|
"content-type": "application/json"
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user