Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/routes/authRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from 'express'
import { register, login } from '../controllers/authController.ts'
import { validateBody } from '../middleware/validation.ts'
import { z } from 'zod'
import { insertUserSchema } from '../db/schema.ts'

const router = Router()

Expand All @@ -23,7 +24,7 @@ const loginSchema = z.object({
})

// Routes
router.post('/register', validateBody(registerSchema), register)
router.post('/register', validateBody(insertUserSchema), register)
router.post('/login', validateBody(loginSchema), login)

export default router
17 changes: 2 additions & 15 deletions src/utils/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SignJWT, jwtVerify, decodeJwt } from 'jose'
import { SignJWT, jwtVerify, decodeJwt, type JWTPayload} from 'jose'
import { createSecretKey } from 'crypto'
import env from '../../env.ts'

export interface JwtPayload {
export interface JwtPayload extends JWTPayload{
id: string
email: string
username: string
Expand Down Expand Up @@ -33,16 +33,3 @@ export const verifyToken = async (token: string): Promise<JwtPayload> => {
username: payload.username as string,
}
}

export const decodeToken = (token: string): JwtPayload | null => {
try {
const payload = decodeJwt(token)
return {
id: payload.id as string,
email: payload.email as string,
username: payload.username as string,
}
} catch {
return null
}
}