WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

JWT token structure not working #14848

@alireza-asgharii

Description

@alireza-asgharii

Documentation Issue

https://payloadcms.com/docs/authentication/jwt#external-jwt-validation
In version 3.2, I was able to create a custom JWT token using this method and use it in my application without any issues. But ever since I updated to the latest version yesterday, generating the token with the same approach results in a 401 error.

Additional Details

  if (!secret) throw new Error("PAYLOAD_SECRET is not defined");
  // The same conversion of Payload to 32-byte key that Payload uses
  return crypto.createHash("sha256").update(secret).digest("hex").slice(0, 32);
};`

`const signingKey = getPayloadSigningKey(process.env.PAYLOAD_SECRET);
    const tokenPayload = {
      id: userDoc.id,
      // If the collection has an email field and saveToJWT is set, set its value
      username: userDoc.username,
      collection: "mini-app-users",
    };```

```const token = jwt.sign(tokenPayload, signingKey, {
      algorithm: "HS256",
      expiresIn: "5h",
    });```

Metadata

Metadata

Assignees

Labels

Bugarea: docsImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions