From 11bd06ccfd532801772ba274d00d0228a3217d0e Mon Sep 17 00:00:00 2001 From: WesleyR10 Date: Wed, 24 Apr 2024 14:13:50 -0300 Subject: [PATCH 1/2] Correction login google --- src/application/infra/oAuth/config/passportConfig.ts | 2 +- src/application/infra/routes/auth/authRouter.ts | 10 +++++----- src/index.ts | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/application/infra/oAuth/config/passportConfig.ts b/src/application/infra/oAuth/config/passportConfig.ts index 3f0b962..3af1597 100644 --- a/src/application/infra/oAuth/config/passportConfig.ts +++ b/src/application/infra/oAuth/config/passportConfig.ts @@ -9,7 +9,7 @@ import { handleGoogleProfile } from "../googleProfileHandler"; fastifyPassport.use(new GoogleStrategy({ clientID: env.googleClientId, clientSecret: env.googleClientSecret, - callbackURL: "https://meetflow.fly.dev/api/auth/google/callback", + callbackURL: "https://api.meetflow.tech/api/auth/google/callback", passReqToCallback: true, }, async (request: any, accessToken: string, refreshToken: string, params: any ,profile: any, done: any) => { diff --git a/src/application/infra/routes/auth/authRouter.ts b/src/application/infra/routes/auth/authRouter.ts index c93f51b..c9c7813 100644 --- a/src/application/infra/routes/auth/authRouter.ts +++ b/src/application/infra/routes/auth/authRouter.ts @@ -20,7 +20,7 @@ const googleAuthOptions = { prompt: "consent", }; -const cookieOptions = { path: "/", maxAge: 7 * 24 * 60 * 60 }; // 7 days +const cookieOptions = { path: "/", domain: ".meetflow.tech", maxAge: 7 * 24 * 60 * 60 }; // 7 dias export async function auth(fastify: FastifyInstance) { fastify.post("/auth/signup", signupPostSchema, signupAdapter()); @@ -44,7 +44,7 @@ export async function auth(fastify: FastifyInstance) { const user = request.user as User; // Extract the scope parameter from the URL - const url = new URL(request.url, "https://meetflow.fly.dev/"); + const url = new URL(request.url, "https://api.meetflow.tech/"); const scopes = url.searchParams.get("scope"); const decodedScopes = decodeURIComponent(scopes || "").split(" "); @@ -58,12 +58,12 @@ export async function auth(fastify: FastifyInstance) { reply.setCookie("meetFlow.user", JSON.stringify(user.user), cookieOptions); } if (user.user.role === "client") { - reply.redirect("http://localhost:5173/dashboard/services"); + reply.redirect("https://www.meetflow.tech/dashboard/services"); } else if (user.user.role === "professional") { if (user.user.myScheduleId) { - reply.redirect("http://localhost:5173/professional/dashboard"); + reply.redirect("https://www.meetflow.tech/professional/dashboard"); } else { - reply.redirect("http://localhost:5173/professional/register/google"); + reply.redirect("https://www.meetflow.tech/professional/register/google"); } } } diff --git a/src/index.ts b/src/index.ts index 4fab730..97b3d60 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,9 +47,10 @@ export const makeFastifyInstance = async (externalMongoClient = null) => { timeWindow: "5 minute", }); await fastify.register(cors, { - origin: "*", + origin: "https://www.meetflow.tech", // Altere para a sua origem exata methods: ["POST", "GET", "PATCH", "DELETE"], allowedHeaders: ["Content-Type", "Authorization", "authorization", "refreshtoken"], + credentials: true, // Permitir cookies }); // if (env.environment === "production") { // await fastify.register(require("@fastify/under-pressure"), { From c2a37df8717c742c10ece6199c9128b7d27bf8cd Mon Sep 17 00:00:00 2001 From: WesleyR10 Date: Thu, 25 Apr 2024 17:20:18 -0300 Subject: [PATCH 2/2] Correction dashboard not utilizing --- src/application/infra/oAuth/google.ts | 4 + src/index.ts | 3 +- .../addAppointmentController.ts | 73 ++++++++++++------- .../controllers/signup/signupController.ts | 22 +++--- 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/application/infra/oAuth/google.ts b/src/application/infra/oAuth/google.ts index 41b325c..c6786bd 100644 --- a/src/application/infra/oAuth/google.ts +++ b/src/application/infra/oAuth/google.ts @@ -20,6 +20,10 @@ export class GoogleOAuthService implements GoogleOAuth { options: {}, }); + if (!account) { + return null; + } + const auth = new google.auth.OAuth2( process.env.GOOGLE_CLIENT_ID, process.env.GOOGLE_CLIENT_SECRET, diff --git a/src/index.ts b/src/index.ts index 97b3d60..99458c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,8 @@ export const makeFastifyInstance = async (externalMongoClient = null) => { timeWindow: "5 minute", }); await fastify.register(cors, { - origin: "https://www.meetflow.tech", // Altere para a sua origem exata + // Como coloco o localhost na origin abaixo + origin: ["https://www.meetflow.tech", "http://localhost:4173", "http://localhost:5173"], // Altere para a sua origem exata methods: ["POST", "GET", "PATCH", "DELETE"], allowedHeaders: ["Content-Type", "Authorization", "authorization", "refreshtoken"], credentials: true, // Permitir cookies diff --git a/src/slices/appointment/controllers/addAppointment/addAppointmentController.ts b/src/slices/appointment/controllers/addAppointment/addAppointmentController.ts index c61ceeb..3aa912b 100644 --- a/src/slices/appointment/controllers/addAppointment/addAppointmentController.ts +++ b/src/slices/appointment/controllers/addAppointment/addAppointmentController.ts @@ -47,37 +47,60 @@ export class AddAppointmentController extends Controller { if(httpRequest?.userId){ // After creating the appointment, create a Google Calendar event const auth = await this.googleOAuthService.getGoogleOAuthToken(httpRequest?.userId); - const calendar = google.calendar({ version: "v3", auth }); + + if (auth) { + const calendar = google.calendar({ version: "v3", auth }); - const event = { - summary: `Meet Flow: ${httpRequest?.body?.serviceName}`, - description: httpRequest?.body?.message, - start: { - dateTime: addHours(parseISO(httpRequest?.body?.initDate), 3), // Adiciona 3 horas - "timeZone": "America/Sao_Paulo", // Fuso horário do Brasil - }, - end: { - dateTime: addHours(parseISO(httpRequest?.body?.endDate), 3), // Adiciona 3 horas - "timeZone": "America/Sao_Paulo", // Fuso horário do Brasil - }, - attendees: [{ email: httpRequest?.body?.clientEmail, displayName: httpRequest?.body?.clientName }], - conferenceData: { - createRequest: { - requestId: appointmentCreated?._id, - conferenceSolutionKey: { - type: "hangoutsMeet", + const event = { + summary: `Meet Flow: ${httpRequest?.body?.serviceName}`, + description: httpRequest?.body?.message, + start: { + dateTime: addHours(parseISO(httpRequest?.body?.initDate), 3), // Adiciona 3 horas + "timeZone": "America/Sao_Paulo", // Fuso horário do Brasil + }, + end: { + dateTime: addHours(parseISO(httpRequest?.body?.endDate), 3), // Adiciona 3 horas + "timeZone": "America/Sao_Paulo", // Fuso horário do Brasil + }, + attendees: [{ email: httpRequest?.body?.clientEmail, displayName: httpRequest?.body?.clientName }], + conferenceData: { + createRequest: { + requestId: appointmentCreated?._id, + conferenceSolutionKey: { + type: "hangoutsMeet", + }, }, }, - }, - }; + }; - await calendar.events.insert({ - calendarId: "primary", - conferenceDataVersion: 1, - requestBody: event, - }); + await calendar.events.insert({ + calendarId: "primary", + conferenceDataVersion: 1, + requestBody: event, + }); + } } return success(appointmentCreated); } } + +/* +if(httpRequest?.userId){ + const account = await this.loadAccount({ + fields: { + createdById: httpRequest?.userId, + provider: "google", + }, + options: {}, + }); + + if (account) { + // After creating the appointment, create a Google Calendar event + const auth = await this.googleOAuthService.getGoogleOAuthToken(httpRequest?.userId); + const calendar = google.calendar({ version: "v3", auth }); + + // ... restante do código para criar o evento no Google Calendar + } +} +*/ \ No newline at end of file diff --git a/src/slices/user/controllers/signup/signupController.ts b/src/slices/user/controllers/signup/signupController.ts index 40ff514..425c007 100644 --- a/src/slices/user/controllers/signup/signupController.ts +++ b/src/slices/user/controllers/signup/signupController.ts @@ -59,16 +59,18 @@ export class SignupController extends Controller { if (httpRequest?.body?.provider === "google") { console.log("provider google", httpRequest?.body?.provider ); const auth = await this.googleOAuthService.getGoogleOAuthToken(userCreated?._id as string); - console.log("auth Controller", auth); - const { access_token, refresh_token } = auth.credentials; - await this.addAccount({ - createdById: userCreated?._id as string, - name: userCreated?.name as string, - refreshToken, - active: true, - expiresAt: addDays(new Date(), 1) as unknown as string, - }); - return success({ user: userCreated, accessToken: access_token, refreshToken:refresh_token }); + if(auth) { + console.log("auth Controller", auth); + const { access_token, refresh_token } = auth.credentials; + await this.addAccount({ + createdById: userCreated?._id as string, + name: userCreated?.name as string, + refreshToken, + active: true, + expiresAt: addDays(new Date(), 1) as unknown as string, + }); + return success({ user: userCreated, accessToken: access_token, refreshToken:refresh_token }); + } } await this.addAccount({