Skip to content

Commit

Permalink
fix(frontend): handle jwt parsing error (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Mar 29, 2021
1 parent a77fe62 commit c455ceb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion targets/frontend/src/lib/auth/jwt.js
@@ -1,7 +1,13 @@
import jwt, { verify } from "jsonwebtoken";

const { HASURA_GRAPHQL_JWT_SECRET, JWT_TOKEN_EXPIRES } = process.env;
const jwtSecret = JSON.parse(HASURA_GRAPHQL_JWT_SECRET);

let jwtSecret;
try {
jwtSecret = JSON.parse(HASURA_GRAPHQL_JWT_SECRET);
} catch (error) {
console.error("[JWT], HASURA_GRAPHQL_JWT_SECRET is not a valid json");
}

export function generateJwtToken(user) {
const user_roles = user.roles.map((role) => {
Expand Down
2 changes: 1 addition & 1 deletion targets/frontend/src/lib/auth/token.js
Expand Up @@ -30,7 +30,7 @@ export async function auth(ctx) {

const cookieHeader = ctx?.req ? { Cookie: ctx.req.headers.cookie } : {};

if (ctx?.req && !cookieHeader.Cookie) {
if (ctx?.req && !cookieHeader.Cookie?.refresh_token) {
console.log("[ auth ] no cookie found -> redirect to login");
ctx.res.writeHead(302, { Location: "/login" });
ctx.res.end();
Expand Down

0 comments on commit c455ceb

Please sign in to comment.