Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use integer for userId in JWT #3883

Closed
wants to merge 1 commit into from
Closed
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 api.planx.uk/modules/auth/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const buildJWTForAPIRole = () =>
const generateHasuraClaimsForUser = (user: User): HasuraClaims => ({
"x-hasura-allowed-roles": getAllowedRolesForUser(user),
"x-hasura-default-role": getDefaultRoleForUser(user),
"x-hasura-user-id": user.id.toString(),
"x-hasura-user-id": user.id,
});

/**
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type HasuraNamespace = "https://hasura.io/jwt/claims";
export type HasuraClaims = {
"x-hasura-allowed-roles": Role[];
"x-hasura-default-role": Role;
"x-hasura-user-id": string;
"x-hasura-user-id": number;
};
export type HasuraJWT = Record<HasuraNamespace, HasuraClaims>;

Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/tests/mockJWT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function getJWT({ role }: { role: Role }) {
"https://hasura.io/jwt/claims": {
"x-hasura-allowed-roles": [role],
"x-hasura-default-role": role,
"x-hasura-user-id": "123",
"x-hasura-user-id": 123,
},
};

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/api-driven/src/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const buildJWT = async (email: string): Promise<string | undefined> => {
const generateHasuraClaimsForUser = (user: User) => ({
"x-hasura-allowed-roles": getAllowedRolesForUser(user),
"x-hasura-default-role": getDefaultRoleForUser(user),
"x-hasura-user-id": user.id.toString(),
"x-hasura-user-id": user.id,
});

/**
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ export async function tearDownTestContext(context: Context) {
}
}

export function generateAuthenticationToken(userId: string) {
export function generateAuthenticationToken(userId: number) {
assert(process.env.JWT_SECRET);
return sign(
{
sub: `${userId}`,
sub: userId.toString(),
"https://hasura.io/jwt/claims": {
"x-hasura-allowed-roles": ["platformAdmin", "public"],
"x-hasura-default-role": "platformAdmin",
"x-hasura-user-id": `${userId}`,
"x-hasura-user-id": userId,
},
},
process.env.JWT_SECRET,
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/helpers/globalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function createAuthenticatedSession({
}): Promise<Page> {
const browserContext = await browser.newContext();
const page = await browserContext.newPage();
const token = generateAuthenticationToken(`${userId}`);
const token = generateAuthenticationToken(userId);
await browserContext.addCookies([
{
name: "jwt",
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export const gqlAdmin = async (query, variables = {}) => {
return json;
};

export const getJWT = (userId) => {
export const getJWT = (userId: number) => {
const data = {
sub: String(userId),
"https://hasura.io/jwt/claims": {
"x-hasura-allowed-roles": ["platformAdmin", "public"],
"x-hasura-default-role": "platformAdmin",
"x-hasura-user-id": String(userId),
"x-hasura-user-id": userId,
},
};

Expand Down
2 changes: 1 addition & 1 deletion hasura.planx.uk/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function buildJWTForRole(role, userId = 1) {
const hasura = {
"x-hasura-allowed-roles": [role],
"x-hasura-default-role": role,
"x-hasura-user-id": userId.toString(),
"x-hasura-user-id": userId,
};

const data = {
Expand Down
Loading