Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/application/infra/oAuth/config/passportConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/application/infra/oAuth/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/application/infra/routes/auth/authRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(" ");
Expand All @@ -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");
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export const makeFastifyInstance = async (externalMongoClient = null) => {
timeWindow: "5 minute",
});
await fastify.register(cors, {
origin: "*",
// 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
});
// if (env.environment === "production") {
// await fastify.register(require("@fastify/under-pressure"), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
*/
22 changes: 12 additions & 10 deletions src/slices/user/controllers/signup/signupController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down