Skip to content

cannot get userinfo from apollo-server-express + subscription #6133

Answered by rahXephonz
rahXephonz asked this question in Q&A
Discussion options

You must be logged in to vote

Oh my god

This caused in getUserFromToken.ts that my jwt_secret from .env didnt read and returning null when im console that.
Its weird so i adding operator OR

updated getUserFromToken

import JWT from "jsonwebtoken";

const JWT_SECRET = process.env.JWT_SECRET || "secret";

export const getUserFromToken = (token: string) => {
  try {
    return JWT.verify(token, JWT_SECRET) as {
      userId: number;
      username: string;
    };
  } catch (error) {
    return null;
  }
};

hmmm weird

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rahXephonz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant