23 lines
500 B
TypeScript
23 lines
500 B
TypeScript
import { jwtVerify } from "jose";
|
|
|
|
export async function decrypt({
|
|
token,
|
|
encodedKey,
|
|
}: {
|
|
token: string;
|
|
encodedKey: string;
|
|
}): Promise<Record<string, any> | null> {
|
|
try {
|
|
const enc = new TextEncoder().encode(encodedKey);
|
|
const { payload } = await jwtVerify(token, enc, {
|
|
algorithms: ["HS256"],
|
|
});
|
|
return (payload.user as Record<string, any>) || null;
|
|
} catch (error) {
|
|
console.error("Gagal verifikasi session", error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// wibu:0.2.82
|