ZH
测试版翻译

@core / auth

1.0.0 ▾
已验证MIT
GitHub

会话 + OAuth(GitHub、Google),基于 Drizzle,支持 Hono 和 Next.js

代码9 个文件上下文约 670 个 token扫描通过

应用 .genpmignore 后将被注入的确切目录树。固定于

src/lib/auth/cookies.ts只读 · 12c4918
// Cookies de sesión y de estado OAuth, sin dependencias de framework (devuelven cabeceras Set-Cookie).
import { SESSION_TTL_MS } from './session.js';

export const SESSION_COOKIE = 'session';

const secure = () => process.env.NODE_ENV === 'production';

export function serializeCookie(name: string, value: string, maxAgeSeconds: number): string {
  const parts = [`${name}=${encodeURIComponent(value)}`, 'Path=/', 'HttpOnly', 'SameSite=Lax', `Max-Age=${maxAgeSeconds}`];
  if (secure()) parts.push('Secure');
  return parts.join('; ');
}

export function parseCookies(header: string | null | undefined): Record<string, string> {
  const out: Record<string, string> = {};
  for (const part of (header ?? '').split(';')) {
    const i = part.indexOf('=');
    if (i < 1) continue;
    try {
      out[part.slice(0, i).trim()] = decodeURIComponent(part.slice(i + 1).trim());
    } catch {
      // cookie mal codificada: se ignora
    }
  }
  return out;
}

export const sessionCookie = (token: string) => serializeCookie(SESSION_COOKIE, token, SESSION_TTL_MS / 1000);
export const clearSessionCookie = () => serializeCookie(SESSION_COOKIE, '', 0);

举报 @core/auth

使用 GitHub 登录后才能举报包。