Search code examples
node.jsexpressjwtexpress-jwt

JSON Web Token (JWT) is too long to pass through client URL? Node.js and Express authentication


I am trying to use JWT to authenticate a user's email address. I cannot use OAuth because a user will be signing up with their work email and will need to verify using that.

I have added a field to my User model called isVerified. I have used mailgun to send an email to the user when they go to sign up that includes a link to a verification page in the form of http://{client_url}/verification/{userToken} where the userToken is a generated token using JSON web token.... the token is created using only the user's id so there is not a lot of information in the payload.

When the user clicks on this link, they are getting a 404 Not Found error. When I manually shorten the userToken in the url, then it properly connects to the correct React Component... How do I solve this issue?

UPDATE: I just got rid of all the periods from the JWT token and it is loading like that.... so it seems to not be an issue with the length but with the periods... My react router Route path is "/verification/:userToken" ... how do I get it to not be affected by the periods?


Solution

  • Since this does not trigger your component to be rendered

    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjIyLCJpYXQiOjE2MTEwMDY5OTUsImV4cCI6MTYxMTAwODE5NX0.D_-RI_YvE6lyHZFtkMizuHxPs3huIE87D6UKFEywYdg

    and this does

    eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

    I would suspect that it somehow worked because you got rid of the dots.

    Make sure the "." in the token prevent the url from matching your "verification/token" route ? I mean react is assuming that

    "verification/eyxxxx.eyzzzz"

    is not a valid route.

    Try calling for example "verification/test.test.test" and see if it renders your component.