MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / createSessionCookie

Method createSessionCookie

lib/models/files.ts:525–554  ·  view source on GitHub ↗
(
    request: Request,
    response: Response,
    fileShareId: string,
    hashedPassword: string,
  )

Source from the content-addressed store, hash-verified

523 }
524
525 static async createSessionCookie(
526 request: Request,
527 response: Response,
528 fileShareId: string,
529 hashedPassword: string,
530 ) {
531 const token = await generateToken<FileShareJwtData['data']>({
532 file_share_id: fileShareId,
533 hashed_password: hashedPassword,
534 });
535
536 const cookie: Cookie = {
537 name: COOKIE_NAME,
538 value: token,
539 expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7), // 7 days
540 path: `/file-share/${fileShareId}`,
541 secure: isRunningLocally(request) ? false : true,
542 httpOnly: true,
543 sameSite: 'Lax',
544 domain: await resolveCookieDomain(request),
545 };
546
547 if (await AppConfig.isCookieDomainSecurityDisabled()) {
548 delete cookie.domain;
549 }
550
551 setCookie(response.headers, cookie);
552
553 return response;
554 }
555
556 static async getDataFromRequest(request: Request): Promise<{ fileShareId: string; hashedPassword: string } | null> {
557 const cookies = getCookies(request.headers);

Callers 1

postFunction · 0.45

Calls 3

isRunningLocallyFunction · 0.90
resolveCookieDomainFunction · 0.90

Tested by

no test coverage detected