api/src/session.js
//At this point, the sign in mutation already verified their credentials. This function sets the login cookie and updates last_login
At this point, the sign in mutation already verified their credentials. This function sets the login cookie and updates last_login
At this point the sign in mutation already verified their credentials . This function sets the login cookie and updates last_login
async function signIn(req, res, user) {
  if (!user) return null;
  [user] = await db.dbRef
    .table('users')
    .where({ uid: user.uid })
    .update({ last_login: new Date().toISOString() })
    .returning("*");
  if (!user) {
    req.user = null;
    return null;
  }
  const sessioniCookie = jwt.sign({}, process.env.JWT_SECRET, {
    issuer: process.env.APP_ORIGIN,
    audience: process.env.APP_NAME,
    subject: user.uid,
    expiresIn: process.env.JWT_EXPIRES
  });
  res.setHeader("Set-Cookie", cookie.serialize(process.env.JWT_COOKIE, sessioniCookie, {
    httpOnly: true,
    maxAge: process.env.JWT_EXPIRES,
    secure: process.env.APP_ENV === "production",
    path: "/"
  }));
  req.user = user;
  return user;
}
async function signIn ( req , res , user ) { if ( ! user ) return null ; [ user ] = await db . dbRef . table ( 'users' ) . where ( { uid : user . uid } ) . update ( { last_login : new Date ( ) . toISOString ( ) } ) . returning ( "*" ) ; if ( ! user ) { req . user = null ; return null ; } const sessioniCookie = jwt . sign ( { } , process . env . JWT_SECRET , { issuer : process . env . APP_ORIGIN , audience : process . env . APP_NAME , subject : user . uid , expiresIn : process . env . JWT_EXPIRES } ) ; res . setHeader ( "Set-Cookie" , cookie . serialize ( process . env . JWT_COOKIE , sessioniCookie , { httpOnly : true , maxAge : process . env . JWT_EXPIRES , secure : process . env . APP_ENV === "production" , path : "/" } ) ) ; req . user = user ; return user ; }
At this point, the sign in mutation already verified their credentials.
At this point the sign in mutation already verified their credentials .