import jwt from "jsonwebtoken";
import { TokenData } from "./types.js";

export function encodeToken(data: TokenData) {
	const token = jwt.sign(data, "yIvbgS$k7Bfc+mpV%TWDZAhje9#uJad4", {
		algorithm: "HS256"
	});
	return token;
}

export function decodeToken(token: string): Partial<TokenData> {
	return jwt.verify(token, "yIvbgS$k7Bfc+mpV%TWDZAhje9#uJad4", {
		algorithms: ["HS256"]
	}) as Partial<TokenData>;
}