diff --git a/src/config.ts b/src/config.ts index 3291de7..eb9bf68 100644 --- a/src/config.ts +++ b/src/config.ts @@ -70,6 +70,7 @@ export const Config = { JWT_SIGNING_SECRET: getEnv("JWT_SIGNING_SECRET"), JWT_EXPIRATION_TIME: "1 day", + PB_JWT_EXPIRATION_TIME: "1 week", S3_ACCESS_KEY: getEnv("S3_ACCESS_KEY"), S3_SECRET_KEY: getEnv("S3_SECRET_KEY"), diff --git a/src/services/auth/auth-router.ts b/src/services/auth/auth-router.ts index 09e06ce..300c9bb 100644 --- a/src/services/auth/auth-router.ts +++ b/src/services/auth/auth-router.ts @@ -7,10 +7,11 @@ import { createGoogleStrategy, getJwtPayloadFromDatabase } from "./auth-utils"; import jsonwebtoken from "jsonwebtoken"; import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; -import { Role } from "../auth/auth-models"; +import { Role, JwtPayloadType } from "../auth/auth-models"; import { AuthRoleChangeRequest } from "./auth-schema"; import { z } from "zod"; import authSponsorRouter from "./sponsor/sponsor-router"; +import { isPuzzleBang } from "../auth/auth-utils"; const authStrategies: Record = {}; @@ -122,11 +123,19 @@ authRouter.get( try { const jwtPayload = ( await getJwtPayloadFromDatabase(userId) - ).toObject(); + ).toObject() as JwtPayloadType; + + // Check if user has PuzzleBang role + const isPB = isPuzzleBang(jwtPayload); + const token = jsonwebtoken.sign( jwtPayload, Config.JWT_SIGNING_SECRET, - { expiresIn: Config.JWT_EXPIRATION_TIME } + { + expiresIn: isPB + ? Config.PB_JWT_EXPIRATION_TIME + : Config.JWT_EXPIRATION_TIME, + } ); const redirectUri = DeviceRedirects[req.params.DEVICE] + `?token=${token}`; diff --git a/src/services/auth/auth-utils.ts b/src/services/auth/auth-utils.ts index ecaa9ce..0c5542b 100644 --- a/src/services/auth/auth-utils.ts +++ b/src/services/auth/auth-utils.ts @@ -61,3 +61,7 @@ export function isStaff(payload?: JwtPayloadType) { export function isAdmin(payload?: JwtPayloadType) { return payload?.roles.includes(Role.Enum.ADMIN); } + +export function isPuzzleBang(payload?: JwtPayloadType) { + return payload?.roles.includes(Role.Enum.PUZZLEBANG); +}