-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Labels
Description
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",
});```