File size: 662 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// @flow
import Keygrip from 'keygrip';
import jwt from 'jsonwebtoken';

export const cookieKeygrip = new Keygrip([process.env.SESSION_COOKIE_SECRET]);

export const getCookies = ({ userId }: { userId: string }) => {
  // The value of our "session" cookie
  const session = new Buffer(
    JSON.stringify({ passport: { user: userId } })
  ).toString('base64');
  // The value of our "session.sig" cookie
  const sessionSig = cookieKeygrip.sign(`session=${session}`);

  return { session, 'session.sig': sessionSig };
};

export const signCookie = (cookie: string) => {
  return jwt.sign({ cookie }, process.env.API_TOKEN_SECRET, {
    expiresIn: '25y',
  });
};