@glinr/theauth-nextjs-auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +230 -0
- package/dist/index.d.ts +290 -0
- package/dist/index.js +459 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +168 -0
- package/dist/middleware.js +161 -0
- package/dist/middleware.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
interface DefaultUser {
|
|
4
|
+
id: string;
|
|
5
|
+
email?: string | null;
|
|
6
|
+
name?: string | null;
|
|
7
|
+
avatarUrl?: string | null;
|
|
8
|
+
}
|
|
9
|
+
interface AuthSession<TUser = DefaultUser> {
|
|
10
|
+
user: TUser;
|
|
11
|
+
/** Parsed from JWT `exp` claim, or null when JWT has no exp. */
|
|
12
|
+
expiresAt: Date | null;
|
|
13
|
+
}
|
|
14
|
+
/** All endpoint path overrides. Defaults to TheAuth/glinr.me conventions. */
|
|
15
|
+
interface AuthEndpoints {
|
|
16
|
+
/** GET — returns current user payload. Default: "/api/auth/me" */
|
|
17
|
+
me: string;
|
|
18
|
+
/** POST body: { refreshToken }. Default: "/api/auth/refresh" */
|
|
19
|
+
refresh: string;
|
|
20
|
+
/** POST — invalidates session on backend. Default: "/api/auth/logout" */
|
|
21
|
+
signOut: string;
|
|
22
|
+
}
|
|
23
|
+
/** Cookie name / prefix overrides. */
|
|
24
|
+
interface AuthCookieConfig {
|
|
25
|
+
/**
|
|
26
|
+
* Prefix used to derive the session + CSRF cookie names.
|
|
27
|
+
* Default: "glinr"
|
|
28
|
+
* Prod: __Host-{prefix}-token / __Host-{prefix}-csrf
|
|
29
|
+
* Dev: {prefix}-token / {prefix}-csrf
|
|
30
|
+
*/
|
|
31
|
+
sessionPrefix: string;
|
|
32
|
+
/** Override the refresh-token cookie name. Default: "{prefix}-refresh-token" */
|
|
33
|
+
refresh: string;
|
|
34
|
+
}
|
|
35
|
+
interface AuthConfig<TUser = DefaultUser> {
|
|
36
|
+
/** Backend URL, no trailing slash. E.g. "https://api.example.com" */
|
|
37
|
+
backendUrl: string;
|
|
38
|
+
/** Public app URL used for Origin / X-Client-Origin headers. */
|
|
39
|
+
appUrl: string;
|
|
40
|
+
/** Tenant identifier sent as X-Tenant-Domain. Optional. */
|
|
41
|
+
tenantDomain?: string;
|
|
42
|
+
/** Endpoint path overrides. Defaults to TheAuth conventions. */
|
|
43
|
+
endpoints?: Partial<AuthEndpoints>;
|
|
44
|
+
/** Cookie name overrides. */
|
|
45
|
+
cookies?: Partial<AuthCookieConfig>;
|
|
46
|
+
/**
|
|
47
|
+
* Skip calling the backend for getServerSession() if the session cache
|
|
48
|
+
* cookie is fresher than this many milliseconds. Set to 0 to disable.
|
|
49
|
+
* Default: 300_000 (5 minutes — matches better-auth's cookie cache TTL).
|
|
50
|
+
*/
|
|
51
|
+
cookieCacheMaxAgeMs?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Proactively refresh the access token when fewer than this many seconds
|
|
54
|
+
* of life remain on the JWT. Default: 60.
|
|
55
|
+
*/
|
|
56
|
+
expiryRefreshBufferS?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Map the raw backend response from the /me endpoint to your TUser shape.
|
|
59
|
+
* If omitted, the raw response is cast to TUser directly.
|
|
60
|
+
*/
|
|
61
|
+
mapUser?: (raw: unknown) => TUser | null;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the app is running on HTTPS. Controls __Host-/plain cookie
|
|
64
|
+
* prefix selection. Auto-detected from NODE_ENV when omitted.
|
|
65
|
+
*/
|
|
66
|
+
isProd?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** Fully resolved config with all defaults applied. */
|
|
69
|
+
interface ResolvedAuthConfig<TUser = DefaultUser> {
|
|
70
|
+
backendUrl: string;
|
|
71
|
+
appUrl: string;
|
|
72
|
+
tenantDomain: string;
|
|
73
|
+
endpoints: AuthEndpoints;
|
|
74
|
+
cookies: AuthCookieConfig & {
|
|
75
|
+
/** Computed full session cookie name (env-aware). */
|
|
76
|
+
sessionName: string;
|
|
77
|
+
/** Computed full CSRF cookie name (env-aware). */
|
|
78
|
+
csrfName: string;
|
|
79
|
+
/** Session cache cookie name. */
|
|
80
|
+
cacheName: string;
|
|
81
|
+
};
|
|
82
|
+
cookieCacheMaxAgeMs: number;
|
|
83
|
+
expiryRefreshBufferS: number;
|
|
84
|
+
mapUser: (raw: unknown) => TUser | null;
|
|
85
|
+
isProd: boolean;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Factory that resolves defaults and returns an immutable config object.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // src/lib/auth/config.ts
|
|
94
|
+
* import "server-only";
|
|
95
|
+
* import { createAuthConfig } from "@glinr/theauth-nextjs-auth";
|
|
96
|
+
*
|
|
97
|
+
* export const authConfig = createAuthConfig({
|
|
98
|
+
* backendUrl: process.env.NEXT_PUBLIC_API_BASE_URL!,
|
|
99
|
+
* appUrl: process.env.NEXT_PUBLIC_APP_URL!,
|
|
100
|
+
* tenantDomain: "myapp.com",
|
|
101
|
+
* mapUser: (raw) => {
|
|
102
|
+
* if (!raw || typeof raw !== "object") return null;
|
|
103
|
+
* const r = raw as Record<string, unknown>;
|
|
104
|
+
* return { id: String(r.id), email: String(r.email ?? ""), name: String(r.name ?? "") };
|
|
105
|
+
* },
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function createAuthConfig<TUser = DefaultUser>(input: AuthConfig<TUser>): ResolvedAuthConfig<TUser>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Minimal JWT utilities — works in Node.js, Edge runtime, and browser.
|
|
113
|
+
* Does NOT verify signatures. Only used to read the `exp` claim for
|
|
114
|
+
* proactive refresh decisions. The backend re-validates every request.
|
|
115
|
+
*/
|
|
116
|
+
/**
|
|
117
|
+
* Returns the unix-seconds `exp` claim from a JWT without verifying its
|
|
118
|
+
* signature, or null if the token is malformed or has no exp claim.
|
|
119
|
+
*/
|
|
120
|
+
declare function readJwtExp(token: string): number | null;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Edge-runtime safe middleware factory.
|
|
124
|
+
* NO `server-only` import — this file must work in the Edge runtime.
|
|
125
|
+
* NO `next/headers` import — cookies are read from NextRequest directly.
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
interface MiddlewareOptions {
|
|
129
|
+
/**
|
|
130
|
+
* Paths that require authentication. On these paths, if the session cannot
|
|
131
|
+
* be established after a refresh attempt, the user is redirected to signInPath.
|
|
132
|
+
* Supports simple prefix matching: "/app" matches "/app", "/app/dashboard", etc.
|
|
133
|
+
*/
|
|
134
|
+
protectedPaths?: string[];
|
|
135
|
+
/**
|
|
136
|
+
* Path to redirect to when authentication is required. Default: "/signin".
|
|
137
|
+
* The original path is appended as `?next=<path>`.
|
|
138
|
+
*/
|
|
139
|
+
signInPath?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Maximum milliseconds to wait for a refresh request before letting the
|
|
142
|
+
* request through unauthenticated. Default: 4000.
|
|
143
|
+
*/
|
|
144
|
+
refreshTimeoutMs?: number;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Middleware factory. Wraps a Next.js middleware with:
|
|
148
|
+
* 1. x-pathname header forwarding (for layouts to build ?next= redirects).
|
|
149
|
+
* 2. Proactive JWT refresh when the access token is missing or expiring.
|
|
150
|
+
* 3. Protected-path redirect to signInPath when auth cannot be established.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* // middleware.ts (project root)
|
|
155
|
+
* import { withAuth } from "@glinr/theauth-nextjs-auth/middleware";
|
|
156
|
+
* import { authConfig } from "@/lib/auth/config";
|
|
157
|
+
*
|
|
158
|
+
* export default withAuth(authConfig, {
|
|
159
|
+
* protectedPaths: ["/app"],
|
|
160
|
+
* signInPath: "/signin",
|
|
161
|
+
* });
|
|
162
|
+
*
|
|
163
|
+
* export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"] };
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function withAuth<TUser>(config: ResolvedAuthConfig<TUser>, options?: MiddlewareOptions): (req: NextRequest) => Promise<NextResponse>;
|
|
167
|
+
|
|
168
|
+
export { type AuthConfig, type AuthSession, type DefaultUser, type ResolvedAuthConfig, createAuthConfig, readJwtExp, withAuth };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
// src/middleware.ts
|
|
4
|
+
|
|
5
|
+
// src/csrf.ts
|
|
6
|
+
function generateCsrfToken() {
|
|
7
|
+
const bytes = new Uint8Array(32);
|
|
8
|
+
crypto.getRandomValues(bytes);
|
|
9
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/jwt.ts
|
|
13
|
+
function readJwtExp(token) {
|
|
14
|
+
const parts = token.split(".");
|
|
15
|
+
if (parts.length !== 3) return null;
|
|
16
|
+
try {
|
|
17
|
+
const payload = parts[1];
|
|
18
|
+
if (!payload) return null;
|
|
19
|
+
const b64 = payload.replace(/-/g, "+").replace(/_/g, "/");
|
|
20
|
+
const padded = b64.padEnd(b64.length + (4 - b64.length % 4) % 4, "=");
|
|
21
|
+
const json = atob(padded);
|
|
22
|
+
const claims = JSON.parse(json);
|
|
23
|
+
return typeof claims.exp === "number" ? claims.exp : null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function isTokenExpiring(token, bufferS) {
|
|
29
|
+
const exp = readJwtExp(token);
|
|
30
|
+
if (exp === null) return false;
|
|
31
|
+
const nowS = Math.floor(Date.now() / 1e3);
|
|
32
|
+
return exp - nowS < bufferS;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/config.ts
|
|
36
|
+
var DEFAULT_COOKIE_CACHE_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
37
|
+
var DEFAULT_EXPIRY_REFRESH_BUFFER_S = 60;
|
|
38
|
+
function createAuthConfig(input) {
|
|
39
|
+
const isProd = input.isProd ?? process.env.NODE_ENV === "production";
|
|
40
|
+
const sessionPrefix = input.cookies?.sessionPrefix ?? "glinr";
|
|
41
|
+
const refreshCookieName = input.cookies?.refresh ?? `${sessionPrefix}-refresh-token`;
|
|
42
|
+
const sessionName = isProd ? `__Host-${sessionPrefix}-token` : `${sessionPrefix}-token`;
|
|
43
|
+
const csrfName = isProd ? `__Host-${sessionPrefix}-csrf` : `${sessionPrefix}-csrf`;
|
|
44
|
+
const cacheName = `${sessionPrefix}-session-cache`;
|
|
45
|
+
const defaultMapUser = (raw) => {
|
|
46
|
+
if (raw === null || raw === void 0) return null;
|
|
47
|
+
return raw;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
backendUrl: input.backendUrl.replace(/\/$/, ""),
|
|
51
|
+
appUrl: input.appUrl.replace(/\/$/, ""),
|
|
52
|
+
tenantDomain: input.tenantDomain ?? "",
|
|
53
|
+
endpoints: {
|
|
54
|
+
me: input.endpoints?.me ?? "/api/auth/me",
|
|
55
|
+
refresh: input.endpoints?.refresh ?? "/api/auth/refresh",
|
|
56
|
+
signOut: input.endpoints?.signOut ?? "/api/auth/logout"
|
|
57
|
+
},
|
|
58
|
+
cookies: {
|
|
59
|
+
sessionPrefix,
|
|
60
|
+
refresh: refreshCookieName,
|
|
61
|
+
sessionName,
|
|
62
|
+
csrfName,
|
|
63
|
+
cacheName
|
|
64
|
+
},
|
|
65
|
+
cookieCacheMaxAgeMs: input.cookieCacheMaxAgeMs ?? DEFAULT_COOKIE_CACHE_MAX_AGE_MS,
|
|
66
|
+
expiryRefreshBufferS: input.expiryRefreshBufferS ?? DEFAULT_EXPIRY_REFRESH_BUFFER_S,
|
|
67
|
+
mapUser: input.mapUser ?? defaultMapUser,
|
|
68
|
+
isProd
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/middleware.ts
|
|
73
|
+
function withAuth(config, options = {}) {
|
|
74
|
+
const { protectedPaths = [], signInPath = "/signin", refreshTimeoutMs = 4e3 } = options;
|
|
75
|
+
return async function authMiddleware(req) {
|
|
76
|
+
const pathname = req.nextUrl.pathname;
|
|
77
|
+
const reqHeaders = new Headers(req.headers);
|
|
78
|
+
reqHeaders.set("x-pathname", pathname);
|
|
79
|
+
const response = NextResponse.next({ request: { headers: reqHeaders } });
|
|
80
|
+
const { sessionPrefix } = config.cookies;
|
|
81
|
+
const accessToken = req.cookies.get(`__Host-${sessionPrefix}-token`)?.value ?? req.cookies.get(`${sessionPrefix}-token`)?.value;
|
|
82
|
+
const refreshToken = req.cookies.get(config.cookies.refresh)?.value;
|
|
83
|
+
const needsRefresh = !accessToken || isTokenExpiring(accessToken, config.expiryRefreshBufferS);
|
|
84
|
+
let hasValidSession = Boolean(accessToken);
|
|
85
|
+
if (needsRefresh && refreshToken) {
|
|
86
|
+
const refreshed = await _tryRefresh(config, refreshToken, refreshTimeoutMs);
|
|
87
|
+
if (refreshed) {
|
|
88
|
+
hasValidSession = true;
|
|
89
|
+
_writeSessionCookies(response, refreshed, config);
|
|
90
|
+
} else if (!accessToken) {
|
|
91
|
+
hasValidSession = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (protectedPaths.length > 0 && !hasValidSession) {
|
|
95
|
+
const isProtected = protectedPaths.some(
|
|
96
|
+
(p) => pathname === p || pathname.startsWith(`${p}/`)
|
|
97
|
+
);
|
|
98
|
+
if (isProtected) {
|
|
99
|
+
const signInUrl = req.nextUrl.clone();
|
|
100
|
+
signInUrl.pathname = signInPath;
|
|
101
|
+
signInUrl.searchParams.set("next", pathname);
|
|
102
|
+
return NextResponse.redirect(signInUrl, { status: 307 });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return response;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
async function _tryRefresh(config, refreshToken, timeoutMs) {
|
|
109
|
+
const controller = new AbortController();
|
|
110
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
111
|
+
try {
|
|
112
|
+
const res = await fetch(`${config.backendUrl}${config.endpoints.refresh}`, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: {
|
|
115
|
+
"Content-Type": "application/json",
|
|
116
|
+
Accept: "application/json",
|
|
117
|
+
Origin: config.appUrl,
|
|
118
|
+
"X-Client-Origin": config.appUrl,
|
|
119
|
+
...config.tenantDomain ? { "X-Tenant-Domain": config.tenantDomain } : {}
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify({ refreshToken }),
|
|
122
|
+
signal: controller.signal
|
|
123
|
+
});
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
if (!res.ok) return null;
|
|
126
|
+
const data = await res.json();
|
|
127
|
+
if (!data.accessToken) return null;
|
|
128
|
+
return {
|
|
129
|
+
accessToken: data.accessToken,
|
|
130
|
+
refreshToken: data.refreshToken,
|
|
131
|
+
csrfToken: generateCsrfToken()
|
|
132
|
+
};
|
|
133
|
+
} catch {
|
|
134
|
+
clearTimeout(timer);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function _writeSessionCookies(response, tokens, config) {
|
|
139
|
+
const sessionOpts = {
|
|
140
|
+
httpOnly: true,
|
|
141
|
+
secure: config.isProd,
|
|
142
|
+
sameSite: "lax",
|
|
143
|
+
path: "/",
|
|
144
|
+
maxAge: 60 * 60 * 24 * 7
|
|
145
|
+
};
|
|
146
|
+
response.cookies.set(config.cookies.sessionName, tokens.accessToken, sessionOpts);
|
|
147
|
+
response.cookies.set(config.cookies.csrfName, tokens.csrfToken, {
|
|
148
|
+
...sessionOpts,
|
|
149
|
+
httpOnly: false
|
|
150
|
+
});
|
|
151
|
+
if (tokens.refreshToken) {
|
|
152
|
+
response.cookies.set(config.cookies.refresh, tokens.refreshToken, {
|
|
153
|
+
...sessionOpts,
|
|
154
|
+
maxAge: 60 * 60 * 24 * 30
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { createAuthConfig, readJwtExp, withAuth };
|
|
160
|
+
//# sourceMappingURL=middleware.js.map
|
|
161
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/csrf.ts","../src/jwt.ts","../src/config.ts","../src/middleware.ts"],"names":[],"mappings":";;;;;AAYO,SAAS,iBAAA,GAA4B;AAC3C,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,KAAA,EAAO,CAAC,MAAM,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,SAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AACzE;;;ACNO,SAAS,WAAW,KAAA,EAA8B;AACxD,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,GAAG,CAAA;AAC7B,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AAC/B,EAAA,IAAI;AACH,IAAA,MAAM,OAAA,GAAU,MAAM,CAAC,CAAA;AACvB,IAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AAErB,IAAA,MAAM,GAAA,GAAM,QAAQ,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACxD,IAAA,MAAM,MAAA,GAAS,GAAA,CAAI,MAAA,CAAO,GAAA,CAAI,MAAA,GAAA,CAAW,IAA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","sourcesContent":["/**\n * CSRF token generation using Web Crypto.\n * Works in Node.js 18+, Edge runtime, and browsers.\n *\n * We use the double-submit cookie pattern:\n * - A short-lived CSRF token is set in a non-httpOnly cookie so JavaScript\n * can read it.\n * - On mutating requests the client echoes it as the X-CSRF-Token header.\n * - The backend compares header value vs. cookie value; they must match.\n * - An attacker on another origin cannot read the cookie, so they cannot\n * forge the header value.\n */\nexport function generateCsrfToken(): string {\n\tconst bytes = new Uint8Array(32);\n\tcrypto.getRandomValues(bytes);\n\treturn Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n","/**\n * Minimal JWT utilities — works in Node.js, Edge runtime, and browser.\n * Does NOT verify signatures. Only used to read the `exp` claim for\n * proactive refresh decisions. The backend re-validates every request.\n */\n\n/**\n * Returns the unix-seconds `exp` claim from a JWT without verifying its\n * signature, or null if the token is malformed or has no exp claim.\n */\nexport function readJwtExp(token: string): number | null {\n\tconst parts = token.split(\".\");\n\tif (parts.length !== 3) return null;\n\ttry {\n\t\tconst payload = parts[1];\n\t\tif (!payload) return null;\n\t\t// base64url → standard base64 → decode\n\t\tconst b64 = payload.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\t\tconst padded = b64.padEnd(b64.length + ((4 - (b64.length % 4)) % 4), \"=\");\n\t\tconst json = atob(padded);\n\t\tconst claims = JSON.parse(json) as { exp?: unknown };\n\t\treturn typeof claims.exp === \"number\" ? claims.exp : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Returns true if the JWT will expire within `bufferS` seconds from now,\n * or has already expired. Returns false for tokens with no exp claim or\n * malformed tokens (let the backend reject them downstream).\n */\nexport function isTokenExpiring(token: string, bufferS: number): boolean {\n\tconst exp = readJwtExp(token);\n\tif (exp === null) return false;\n\tconst nowS = Math.floor(Date.now() / 1000);\n\treturn exp - nowS < bufferS;\n}\n","import type { AuthConfig, DefaultUser, ResolvedAuthConfig } from \"./types.js\";\n\nconst DEFAULT_COOKIE_CACHE_MAX_AGE_MS = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_EXPIRY_REFRESH_BUFFER_S = 60;\n\n/**\n * Factory that resolves defaults and returns an immutable config object.\n *\n * @example\n * ```ts\n * // src/lib/auth/config.ts\n * import \"server-only\";\n * import { createAuthConfig } from \"@glinr/theauth-nextjs-auth\";\n *\n * export const authConfig = createAuthConfig({\n * backendUrl: process.env.NEXT_PUBLIC_API_BASE_URL!,\n * appUrl: process.env.NEXT_PUBLIC_APP_URL!,\n * tenantDomain: \"myapp.com\",\n * mapUser: (raw) => {\n * if (!raw || typeof raw !== \"object\") return null;\n * const r = raw as Record<string, unknown>;\n * return { id: String(r.id), email: String(r.email ?? \"\"), name: String(r.name ?? \"\") };\n * },\n * });\n * ```\n */\nexport function createAuthConfig<TUser = DefaultUser>(\n\tinput: AuthConfig<TUser>,\n): ResolvedAuthConfig<TUser> {\n\tconst isProd = input.isProd ?? process.env.NODE_ENV === \"production\";\n\n\tconst sessionPrefix = input.cookies?.sessionPrefix ?? \"glinr\";\n\tconst refreshCookieName = input.cookies?.refresh ?? `${sessionPrefix}-refresh-token`;\n\n\tconst sessionName = isProd ? `__Host-${sessionPrefix}-token` : `${sessionPrefix}-token`;\n\tconst csrfName = isProd ? `__Host-${sessionPrefix}-csrf` : `${sessionPrefix}-csrf`;\n\tconst cacheName = `${sessionPrefix}-session-cache`;\n\n\tconst defaultMapUser = (raw: unknown): TUser | null => {\n\t\tif (raw === null || raw === undefined) return null;\n\t\treturn raw as TUser;\n\t};\n\n\treturn {\n\t\tbackendUrl: input.backendUrl.replace(/\\/$/, \"\"),\n\t\tappUrl: input.appUrl.replace(/\\/$/, \"\"),\n\t\ttenantDomain: input.tenantDomain ?? \"\",\n\t\tendpoints: {\n\t\t\tme: input.endpoints?.me ?? \"/api/auth/me\",\n\t\t\trefresh: input.endpoints?.refresh ?? \"/api/auth/refresh\",\n\t\t\tsignOut: input.endpoints?.signOut ?? \"/api/auth/logout\",\n\t\t},\n\t\tcookies: {\n\t\t\tsessionPrefix,\n\t\t\trefresh: refreshCookieName,\n\t\t\tsessionName,\n\t\t\tcsrfName,\n\t\t\tcacheName,\n\t\t},\n\t\tcookieCacheMaxAgeMs: input.cookieCacheMaxAgeMs ?? DEFAULT_COOKIE_CACHE_MAX_AGE_MS,\n\t\texpiryRefreshBufferS: input.expiryRefreshBufferS ?? DEFAULT_EXPIRY_REFRESH_BUFFER_S,\n\t\tmapUser: input.mapUser ?? defaultMapUser,\n\t\tisProd,\n\t};\n}\n","/**\n * Edge-runtime safe middleware factory.\n * NO `server-only` import — this file must work in the Edge runtime.\n * NO `next/headers` import — cookies are read from NextRequest directly.\n */\n\nimport type { NextRequest, NextResponse as NextResponseType } from \"next/server\";\nimport { NextResponse } from \"next/server\";\nimport { generateCsrfToken } from \"./csrf.js\";\nimport { isTokenExpiring } from \"./jwt.js\";\nimport type { ResolvedAuthConfig } from \"./types.js\";\n\n// createAuthConfig is a pure function — safe to use in Edge runtime.\nexport { createAuthConfig } from \"./config.js\";\nexport { readJwtExp } from \"./jwt.js\";\nexport type { AuthConfig, AuthSession, DefaultUser, ResolvedAuthConfig } from \"./types.js\";\n\ninterface MiddlewareOptions {\n\t/**\n\t * Paths that require authentication. On these paths, if the session cannot\n\t * be established after a refresh attempt, the user is redirected to signInPath.\n\t * Supports simple prefix matching: \"/app\" matches \"/app\", \"/app/dashboard\", etc.\n\t */\n\tprotectedPaths?: string[];\n\t/**\n\t * Path to redirect to when authentication is required. Default: \"/signin\".\n\t * The original path is appended as `?next=<path>`.\n\t */\n\tsignInPath?: string;\n\t/**\n\t * Maximum milliseconds to wait for a refresh request before letting the\n\t * request through unauthenticated. Default: 4000.\n\t */\n\trefreshTimeoutMs?: number;\n}\n\ninterface RefreshTokenResponse {\n\taccessToken?: string;\n\trefreshToken?: string;\n}\n\n/**\n * Middleware factory. Wraps a Next.js middleware with:\n * 1. x-pathname header forwarding (for layouts to build ?next= redirects).\n * 2. Proactive JWT refresh when the access token is missing or expiring.\n * 3. Protected-path redirect to signInPath when auth cannot be established.\n *\n * @example\n * ```ts\n * // middleware.ts (project root)\n * import { withAuth } from \"@glinr/theauth-nextjs-auth/middleware\";\n * import { authConfig } from \"@/lib/auth/config\";\n *\n * export default withAuth(authConfig, {\n * protectedPaths: [\"/app\"],\n * signInPath: \"/signin\",\n * });\n *\n * export const config = { matcher: [\"/((?!_next/static|_next/image|favicon.ico).*)\"] };\n * ```\n */\nexport function withAuth<TUser>(\n\tconfig: ResolvedAuthConfig<TUser>,\n\toptions: MiddlewareOptions = {},\n): (req: NextRequest) => Promise<NextResponseType> {\n\tconst { protectedPaths = [], signInPath = \"/signin\", refreshTimeoutMs = 4000 } = options;\n\n\treturn async function authMiddleware(req: NextRequest): Promise<NextResponseType> {\n\t\tconst pathname = req.nextUrl.pathname;\n\n\t\t// Forward pathname so RSCs can construct next= redirect URLs.\n\t\tconst reqHeaders = new Headers(req.headers);\n\t\treqHeaders.set(\"x-pathname\", pathname);\n\n\t\tconst response = NextResponse.next({ request: { headers: reqHeaders } });\n\n\t\t// Read access token from request cookies (both __Host- and plain variants).\n\t\tconst { sessionPrefix } = config.cookies;\n\t\tconst accessToken =\n\t\t\treq.cookies.get(`__Host-${sessionPrefix}-token`)?.value ??\n\t\t\treq.cookies.get(`${sessionPrefix}-token`)?.value;\n\t\tconst refreshToken = req.cookies.get(config.cookies.refresh)?.value;\n\n\t\tconst needsRefresh = !accessToken || isTokenExpiring(accessToken, config.expiryRefreshBufferS);\n\n\t\t// Start optimistically: any existing token (even an expiring one) counts as valid\n\t\t// until we confirm otherwise. This prevents bouncing users to /signin on transient\n\t\t// refresh failures (network blips, backend hiccups) when their token is still\n\t\t// accepted by the backend for the expiryRefreshBufferS grace window.\n\t\tlet hasValidSession = Boolean(accessToken);\n\n\t\tif (needsRefresh && refreshToken) {\n\t\t\tconst refreshed = await _tryRefresh(config, refreshToken, refreshTimeoutMs);\n\t\t\tif (refreshed) {\n\t\t\t\thasValidSession = true;\n\t\t\t\t_writeSessionCookies(response, refreshed, config);\n\t\t\t} else if (!accessToken) {\n\t\t\t\t// No existing token at all AND refresh failed → definitely unauthenticated.\n\t\t\t\thasValidSession = false;\n\t\t\t}\n\t\t\t// If we had a (possibly expiring) token and refresh failed, keep\n\t\t\t// hasValidSession=true and let the backend validate it downstream.\n\t\t}\n\n\t\t// Redirect unauthenticated users away from protected paths.\n\t\tif (protectedPaths.length > 0 && !hasValidSession) {\n\t\t\tconst isProtected = protectedPaths.some(\n\t\t\t\t(p) => pathname === p || pathname.startsWith(`${p}/`),\n\t\t\t);\n\t\t\tif (isProtected) {\n\t\t\t\tconst signInUrl = req.nextUrl.clone();\n\t\t\t\tsignInUrl.pathname = signInPath;\n\t\t\t\tsignInUrl.searchParams.set(\"next\", pathname);\n\t\t\t\treturn NextResponse.redirect(signInUrl, { status: 307 });\n\t\t\t}\n\t\t}\n\n\t\treturn response;\n\t};\n}\n\nasync function _tryRefresh<TUser>(\n\tconfig: ResolvedAuthConfig<TUser>,\n\trefreshToken: string,\n\ttimeoutMs: number,\n): Promise<{ accessToken: string; refreshToken?: string; csrfToken: string } | null> {\n\tconst controller = new AbortController();\n\tconst timer = setTimeout(() => controller.abort(), timeoutMs);\n\n\ttry {\n\t\tconst res = await fetch(`${config.backendUrl}${config.endpoints.refresh}`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\tAccept: \"application/json\",\n\t\t\t\tOrigin: config.appUrl,\n\t\t\t\t\"X-Client-Origin\": config.appUrl,\n\t\t\t\t...(config.tenantDomain ? { \"X-Tenant-Domain\": config.tenantDomain } : {}),\n\t\t\t},\n\t\t\tbody: JSON.stringify({ refreshToken }),\n\t\t\tsignal: controller.signal,\n\t\t});\n\n\t\tclearTimeout(timer);\n\t\tif (!res.ok) return null;\n\n\t\tconst data = (await res.json()) as RefreshTokenResponse;\n\t\tif (!data.accessToken) return null;\n\n\t\treturn {\n\t\t\taccessToken: data.accessToken,\n\t\t\trefreshToken: data.refreshToken,\n\t\t\tcsrfToken: generateCsrfToken(),\n\t\t};\n\t} catch {\n\t\tclearTimeout(timer);\n\t\treturn null;\n\t}\n}\n\nfunction _writeSessionCookies<TUser>(\n\tresponse: NextResponseType,\n\ttokens: { accessToken: string; refreshToken?: string; csrfToken: string },\n\tconfig: ResolvedAuthConfig<TUser>,\n): void {\n\tconst sessionOpts = {\n\t\thttpOnly: true,\n\t\tsecure: config.isProd,\n\t\tsameSite: \"lax\" as const,\n\t\tpath: \"/\",\n\t\tmaxAge: 60 * 60 * 24 * 7,\n\t};\n\n\tresponse.cookies.set(config.cookies.sessionName, tokens.accessToken, sessionOpts);\n\tresponse.cookies.set(config.cookies.csrfName, tokens.csrfToken, {\n\t\t...sessionOpts,\n\t\thttpOnly: false,\n\t});\n\n\tif (tokens.refreshToken) {\n\t\tresponse.cookies.set(config.cookies.refresh, tokens.refreshToken, {\n\t\t\t...sessionOpts,\n\t\t\tmaxAge: 60 * 60 * 24 * 30,\n\t\t});\n\t}\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@glinr/theauth-nextjs-auth",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Next.js adapter for TheAuth-style external auth backends — cookies, refresh, CSRF, getServerSession, middleware.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./middleware": {
|
|
15
|
+
"types": "./dist/middleware.d.ts",
|
|
16
|
+
"import": "./dist/middleware.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"theauth",
|
|
24
|
+
"nextjs",
|
|
25
|
+
"auth",
|
|
26
|
+
"session",
|
|
27
|
+
"cookies",
|
|
28
|
+
"middleware"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"author": "TheAuth <support@glincker.com>",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/glincker/theauth.git",
|
|
35
|
+
"directory": "packages/adapters/nextjs-auth"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"next": ">=14.0.0",
|
|
39
|
+
"react": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/react": "^19.0.0",
|
|
43
|
+
"next": "^15.0.0",
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"typescript": "^5.0.0",
|
|
46
|
+
"tsup": "^8.0.0",
|
|
47
|
+
"vitest": "^3.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"test": "vitest run --config vitest.config.ts"
|
|
53
|
+
}
|
|
54
|
+
}
|