From f1951fef57c96906969cc473dc467296be004579 Mon Sep 17 00:00:00 2001 From: Aydan Pirani Date: Thu, 11 Apr 2024 02:54:03 -0500 Subject: [PATCH] Added support for dev auth endpoint --- src/config.ts | 1 + src/services/auth/auth-router.ts | 6 +++++- src/services/auth/auth-utils.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index deb7dc2..5d6d7ae 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,4 +27,5 @@ export const Config = { export const DeviceRedirects: Record = { web: "https://www.google.com/", + dev: "http://127.0.0.1:3000/auth/dev/" }; diff --git a/src/services/auth/auth-router.ts b/src/services/auth/auth-router.ts index 6a33379..92d376c 100644 --- a/src/services/auth/auth-router.ts +++ b/src/services/auth/auth-router.ts @@ -51,7 +51,7 @@ authRouter.get( try { const jwtPayload = (await getJwtPayloadFromDatabase(userId)).toObject(); const token = jsonwebtoken.sign(jwtPayload, Config.JWT_SIGNING_SECRET, { expiresIn: Config.JWT_EXPIRATION_TIME }); - const redirectUri = `${DeviceRedirects[req.params.DEVICE]}/token=${token}`; + const redirectUri = DeviceRedirects[req.params.DEVICE] + `token=${token}`; return res.redirect(redirectUri); } catch (error) { next(error); @@ -59,4 +59,8 @@ authRouter.get( } ); +authRouter.get("/dev/", (req, res) => { + return res.status(StatusCodes.OK).json({"Token": req.headers.authorization}); +}) + export default authRouter; diff --git a/src/services/auth/auth-utils.ts b/src/services/auth/auth-utils.ts index 08e82ab..d163571 100644 --- a/src/services/auth/auth-utils.ts +++ b/src/services/auth/auth-utils.ts @@ -9,7 +9,7 @@ export function createGoogleStrategy(device: string) { { clientID: Config.CLIENT_ID, clientSecret: Config.CLIENT_SECRET, - callbackURL: `${Config.AUTH_CALLBACK_URI_BASE}${device}`, + callbackURL: Config.AUTH_CALLBACK_URI_BASE + device, }, // Strategy -> insert user into database if they don't exist