Files
freeCodeCamp/api/src/utils/user-token.ts
Naomi Carrigan 0aa1ad0d09 feat: require JSDoc in new api (#50429)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2023-08-03 21:50:54 +05:30

14 lines
402 B
TypeScript

import jwt from 'jsonwebtoken';
import { JWT_SECRET } from './env';
/**
* Encode an id into a JWT (the naming suggests it's a user token, but it's the
* id of the UserToken document).
* @param userToken A token id to encode.
* @returns An encoded object with the userToken property.
*/
export function encodeUserToken(userToken: string): string {
return jwt.sign({ userToken }, JWT_SECRET);
}