Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8ac6ee515 |
@@ -28,7 +28,7 @@ function signTokens(
|
|||||||
|
|
||||||
const refreshToken = fastify.jwt.sign(
|
const refreshToken = fastify.jwt.sign(
|
||||||
{ ...payload, type: 'refresh' },
|
{ ...payload, type: 'refresh' },
|
||||||
{ secret: config.jwt.refreshSecret, expiresIn: config.jwt.refreshExpiresIn }
|
{ expiresIn: config.jwt.refreshExpiresIn }
|
||||||
)
|
)
|
||||||
|
|
||||||
return { accessToken, refreshToken }
|
return { accessToken, refreshToken }
|
||||||
@@ -157,8 +157,7 @@ export default async function authRoutes(fastify: FastifyInstance) {
|
|||||||
let payload: JwtPayload & { type?: string }
|
let payload: JwtPayload & { type?: string }
|
||||||
try {
|
try {
|
||||||
payload = fastify.jwt.verify<JwtPayload & { type?: string }>(
|
payload = fastify.jwt.verify<JwtPayload & { type?: string }>(
|
||||||
body.data.refreshToken,
|
body.data.refreshToken
|
||||||
{ secret: config.jwt.refreshSecret }
|
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
return reply.code(401).send({ success: false, error: 'Invalid or expired refresh token' })
|
return reply.code(401).send({ success: false, error: 'Invalid or expired refresh token' })
|
||||||
@@ -183,7 +182,7 @@ export default async function authRoutes(fastify: FastifyInstance) {
|
|||||||
const accessToken = fastify.jwt.sign(newPayload, { expiresIn: config.jwt.expiresIn })
|
const accessToken = fastify.jwt.sign(newPayload, { expiresIn: config.jwt.expiresIn })
|
||||||
const newRefresh = fastify.jwt.sign(
|
const newRefresh = fastify.jwt.sign(
|
||||||
{ ...newPayload, type: 'refresh' },
|
{ ...newPayload, type: 'refresh' },
|
||||||
{ secret: config.jwt.refreshSecret, expiresIn: config.jwt.refreshExpiresIn }
|
{ expiresIn: config.jwt.refreshExpiresIn }
|
||||||
)
|
)
|
||||||
|
|
||||||
const expiresAt = new Date()
|
const expiresAt = new Date()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { FastifyInstance } from 'fastify'
|
import type { FastifyInstance } from 'fastify'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { requireAdmin } from '../../middleware/auth.js'
|
import { requireAdmin } from '../../middleware/auth.js'
|
||||||
import { exec, MANAGED_SERVICES as _ } from '../../core/exec.js'
|
import { exec } from '../../core/exec.js'
|
||||||
import { getServiceStatus, MANAGED_SERVICES } from '../../core/system.js'
|
import { getServiceStatus, MANAGED_SERVICES } from '../../core/system.js'
|
||||||
|
|
||||||
const ServiceActionSchema = z.object({
|
const ServiceActionSchema = z.object({
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ export interface JwtPayload {
|
|||||||
exp?: number
|
exp?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Fastify type augmentation ────────────────────────────────────────────────
|
// ─── @fastify/jwt type augmentation ───────────────────────────────────────────
|
||||||
|
|
||||||
declare module 'fastify' {
|
declare module '@fastify/jwt' {
|
||||||
interface FastifyRequest {
|
interface FastifyJWT {
|
||||||
user?: JwtPayload
|
payload: JwtPayload
|
||||||
|
user: JwtPayload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user