EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
jobhash.js
Go to the documentation of this file.
1// backend/utils/jobhash.js
2const crypto = require("crypto");
3
4/**
5 *
6 * @param payload
7 */
8function generateBuilderKey(payload) {
9 const expiresAt = Date.now() + 1000 * 60 * 60 * 24 * 7; // 7 days
10
11 const raw = JSON.stringify({
12 ...payload,
13 exp: expiresAt
14 });
15
16 return Buffer.from(raw).toString("base64url");
17}
18
19/**
20 *
21 * @param key
22 */
23function decodeBuilderKey(key) {
24 try {
25 return JSON.parse(Buffer.from(key, "base64url").toString());
26 } catch {
27 return null;
28 }
29}
30
31module.exports = { generateBuilderKey, decodeBuilderKey };