import jwt from 'jsonwebtoken'
import type {StringValue} from "ms";
const {sign, verify} = jwt


export const generateAccessToken = (payload: object) => {
    const {jwt: config} = useRuntimeConfig()
    return sign(payload, config.secret, { expiresIn: config.accessExpiresIn as StringValue })
}

export const generateRefreshToken = (payload: object) => {
    const {jwt: config} = useRuntimeConfig()
    return sign(payload, config.secret, { expiresIn: config.refreshExpiresIn as StringValue })
}

export const verifyToken = (token: string) => {
    const {jwt: config} = useRuntimeConfig()
    return verify(token, config.secret) // 返回解码后的payload
}
