mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Restructure codebase to use src directory
This commit is contained in:
23
src/config/jwt/index.ts
Normal file
23
src/config/jwt/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { BasicUserInfoSchema } from '@/config/auth/types';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { z } from 'zod';
|
||||
import { CONFIRMATION_TOKEN_SECRET } from '../env';
|
||||
|
||||
type User = z.infer<typeof BasicUserInfoSchema>;
|
||||
|
||||
export const generateConfirmationToken = (user: User) => {
|
||||
const token = jwt.sign(user, CONFIRMATION_TOKEN_SECRET, { expiresIn: '30m' });
|
||||
return token;
|
||||
};
|
||||
|
||||
export const verifyConfirmationToken = (token: string) => {
|
||||
const decoded = jwt.verify(token, CONFIRMATION_TOKEN_SECRET);
|
||||
|
||||
const parsed = BasicUserInfoSchema.safeParse(decoded);
|
||||
|
||||
if (!parsed.success) {
|
||||
throw new Error('Invalid token');
|
||||
}
|
||||
|
||||
return parsed.data;
|
||||
};
|
||||
Reference in New Issue
Block a user