Skip to content

Commit

Permalink
fix: Drop expiry from internal only JWT (#4207)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jan 25, 2025
1 parent 24fdb28 commit 5607aff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions api.planx.uk/modules/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { $api } from "../../client/index.js";
import type { User, Role } from "@opensystemslab/planx-core/types";
import type { HasuraClaims, JWTData } from "./types.js";

export const buildJWT = async (email: string): Promise<string | undefined> => {
export const buildUserJWT = async (
email: string,
): Promise<string | undefined> => {
const user = await $api.user.getByEmail(email);
if (!user) return;

Expand All @@ -28,7 +30,6 @@ export const buildJWTForAPIRole = () =>
},
},
process.env.JWT_SECRET!,
{ expiresIn: "24h" },
);

const generateHasuraClaimsForUser = (user: User): HasuraClaims => ({
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/auth/strategy/google.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
import { buildJWT } from "../service.js";
import { buildUserJWT } from "../service.js";

export const googleStrategy = new GoogleStrategy(
{
Expand All @@ -11,7 +11,7 @@ export const googleStrategy = new GoogleStrategy(
const { email } = profile._json;
if (!email) throw Error("Unable to authenticate without email");

const jwt = await buildJWT(email);
const jwt = await buildUserJWT(email);

if (!jwt) {
return done({
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/auth/strategy/microsoft-oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
StrategyVerifyCallbackReq,
} from "openid-client";
import { Strategy } from "openid-client";
import { buildJWT } from "../service.js";
import { buildUserJWT } from "../service.js";

export const MICROSOFT_OPENID_CONFIG_URL =
"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration";
Expand Down Expand Up @@ -70,7 +70,7 @@ const verifyCallback: StrategyVerifyCallbackReq<Express.User> = async (
return done(new Error("Unable to authenticate without email"));
}

const jwt = await buildJWT(email);
const jwt = await buildUserJWT(email);
if (!jwt) {
return done({
status: 404,
Expand Down

0 comments on commit 5607aff

Please sign in to comment.