Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Covers OAuth2, JWT, RBAC, session management, and PKCE authentication patterns with TypeScript code examples.
Use this skill ↓73% 86%+14 ptsof test cases passed
Passed 19 of 22 test cases with the skill, and 16 of 22 without it.
3 of 3 safety checks passed
Not used yet
import jwt from "jsonwebtoken";
interface TokenPayload {
sub: string;
email: string;
roles: string[];
}
function generateTokens(user: User) {
const accessToken = jwt.sign(
{ sub: user.id, email: user.email, roles: user.roles },
process.env.JWT_SECRET!,
{ expiresIn: "15m", issuer: "auth-service" }
);
const refreshToken = jwt.sign(
{ sub: user.id, tokenVersion: user.tokenVersion },
process.env.REFRESH_SECRET!,
{ expiresIn: "7d", issuer: "auth-service" }
);
return { accessToken, refreshToken };
}
function verifyAccessToken(token: string): TokenPayload {
return jwt.verify(token, process.env.JWT_SECRET!, {
issuer: "auth-service",
}) as TokenPayload;
}
Short-lived access tokens (15 minutes) with longer-lived refresh tokens (7 days). Store refresh tokens in HTTP-only cookies.
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.