redirect urls

main
alex 2024-01-14 19:24:54 +01:00
parent 185e6e7dcc
commit 11b7207501
3 changed files with 36 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import express, { Express, Request } from "express";
import express, { Express } from "express";
import dotenv from "dotenv";
import bodyParser from "body-parser";
import swaggerUI from "swagger-ui-express";

View File

@ -1,2 +1,33 @@
import { Request, Response } from "express";
import logger from "../logger/logger";
import Store from "../models/store";
import { getUserSession } from "../utils/utils";
// this request is needed to get the store id after the user has connected his calendar to redirect him back to the calendar page
export async function GetStoreId(req: Request, res: Response) {
try {
const userSession = await getUserSession(req);
if (!userSession) {
return res.status(401).send({ err: "unauthorized" });
}
// check if user has a store
const store = await Store.findOne({
where: {
owner_user_id: userSession.user_id,
},
attributes: ["store_id"],
});
if (!store) {
return res.status(401).send({ err: "unauthorized" });
}
res.status(200).send({ storeId: store.store_id });
} catch (error) {
logger.error(error);
res.status(500).send({ err: "invalid request" });
}
}

View File

@ -21,17 +21,16 @@ router.get(
router.get(
"/auth/google/callback",
passport.authenticate("google", {
failureRedirect:
/* "https://customerdashboard.ex.umbach.dev/store/calendar/failed" */ "/login",
failureRedirect: process.env.PASSPORT_FAILURE_REDIRECT_URL as string,
}),
function (req, res) {
// Successful authentication, redirect home.
console.log("req.user", req.user);
logger.info("req.user", req.user);
res.redirect(
/* "https://customerdashboard.ex.umbach.dev/store/calendar/finish" */ "/"
);
res.redirect(process.env.PASSPORT_SUCCESS_REDIRECT_URL as string);
}
);
router.get("/store", calendarController.GetStoreId);
export default router;