azirid-react 0.11.0 → 0.11.2
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/README.md +25 -8
- package/dist/index.cjs +34 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/dist/next-handlers.cjs +148 -0
- package/dist/next-handlers.cjs.map +1 -0
- package/dist/next-handlers.js +138 -0
- package/dist/next-handlers.js.map +1 -0
- package/dist/next-proxy.cjs +45 -0
- package/dist/next-proxy.cjs.map +1 -0
- package/dist/next-proxy.d.cts +79 -0
- package/dist/next-proxy.d.ts +79 -0
- package/dist/next-proxy.js +40 -0
- package/dist/next-proxy.js.map +1 -0
- package/dist/next.cjs +1 -3
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +44 -25
- package/dist/next.d.ts +44 -25
- package/dist/next.js +1 -3
- package/dist/next.js.map +1 -1
- package/package.json +21 -1
- package/dist/server.d.cts +0 -102
- package/dist/server.d.ts +0 -102
package/dist/server.d.cts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side utilities for Next.js (App Router).
|
|
3
|
-
*
|
|
4
|
-
* Use this entry point in Server Components, Server Actions, and Route Handlers
|
|
5
|
-
* to read the authenticated user's session token from the httpOnly `__session` cookie.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* // lib/access-server.ts
|
|
10
|
-
* import { cookies } from "next/headers";
|
|
11
|
-
* import { createServerAccess } from "azirid-react/server";
|
|
12
|
-
* export const { getSessionToken } = createServerAccess({ cookies });
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* // app/actions/profile.ts
|
|
17
|
-
* "use server";
|
|
18
|
-
* import { getSessionToken } from "@/lib/access-server";
|
|
19
|
-
*
|
|
20
|
-
* export async function getProfile() {
|
|
21
|
-
* const token = await getSessionToken();
|
|
22
|
-
* if (!token) throw new Error("Not authenticated");
|
|
23
|
-
*
|
|
24
|
-
* const res = await fetch("https://api.myapp.com/v1/users/auth/me", {
|
|
25
|
-
* headers: { Authorization: `Bearer ${token}` },
|
|
26
|
-
* });
|
|
27
|
-
* return res.json();
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @packageDocumentation
|
|
32
|
-
*/
|
|
33
|
-
/** Minimal cookie store interface (subset of Next.js ReadonlyRequestCookies) */
|
|
34
|
-
interface CookieStore {
|
|
35
|
-
get(name: string): {
|
|
36
|
-
value: string;
|
|
37
|
-
} | undefined;
|
|
38
|
-
}
|
|
39
|
-
/** The `cookies` function from `next/headers` */
|
|
40
|
-
type CookiesFn = () => CookieStore | Promise<CookieStore>;
|
|
41
|
-
interface ServerAccessOptions {
|
|
42
|
-
/**
|
|
43
|
-
* The `cookies` function imported from `next/headers`.
|
|
44
|
-
* Required — pass it explicitly to avoid bundler issues with dynamic imports.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* import { cookies } from "next/headers";
|
|
49
|
-
* createServerAccess({ cookies });
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
cookies: CookiesFn;
|
|
53
|
-
/**
|
|
54
|
-
* Name of the httpOnly cookie that carries the access token.
|
|
55
|
-
* Must match the cookie set by the Azirid API.
|
|
56
|
-
* @default "__session"
|
|
57
|
-
*/
|
|
58
|
-
cookieName?: string;
|
|
59
|
-
}
|
|
60
|
-
interface ServerAccess {
|
|
61
|
-
/**
|
|
62
|
-
* Read the raw JWT access token from the session cookie.
|
|
63
|
-
* Returns `null` when no cookie is present or when called
|
|
64
|
-
* outside a Next.js server context.
|
|
65
|
-
*/
|
|
66
|
-
getSessionToken: () => Promise<string | null>;
|
|
67
|
-
/** Alias for {@link getSessionToken}. */
|
|
68
|
-
getAccessToken: () => Promise<string | null>;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Create server-side helpers bound to the session cookie.
|
|
72
|
-
*
|
|
73
|
-
* Call once at module scope, then use the returned functions
|
|
74
|
-
* in any Server Component, Server Action, or Route Handler.
|
|
75
|
-
*/
|
|
76
|
-
declare function createServerAccess(options: ServerAccessOptions): ServerAccess;
|
|
77
|
-
interface SessionSyncOptions {
|
|
78
|
-
/** Cookie name (default: "__session") */
|
|
79
|
-
cookieName?: string;
|
|
80
|
-
/** Set Secure flag on cookie (default: false) */
|
|
81
|
-
secure?: boolean;
|
|
82
|
-
/** Cookie max age in seconds (default: 3600 = 1h) */
|
|
83
|
-
maxAge?: number;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Create a route handler that syncs the access token to a local httpOnly cookie.
|
|
87
|
-
*
|
|
88
|
-
* Use this in a Next.js App Router route to bridge cross-origin sessions:
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* // app/api/auth/session/route.ts
|
|
93
|
-
* import { createSessionSyncHandler } from "azirid-react/server";
|
|
94
|
-
* export const { POST, DELETE } = createSessionSyncHandler();
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
declare function createSessionSyncHandler(options?: SessionSyncOptions): {
|
|
98
|
-
POST(req: Request): Promise<Response>;
|
|
99
|
-
DELETE(): Promise<Response>;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export { type ServerAccess, type ServerAccessOptions, type SessionSyncOptions, createServerAccess, createSessionSyncHandler };
|
package/dist/server.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Server-side utilities for Next.js (App Router).
|
|
3
|
-
*
|
|
4
|
-
* Use this entry point in Server Components, Server Actions, and Route Handlers
|
|
5
|
-
* to read the authenticated user's session token from the httpOnly `__session` cookie.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* // lib/access-server.ts
|
|
10
|
-
* import { cookies } from "next/headers";
|
|
11
|
-
* import { createServerAccess } from "azirid-react/server";
|
|
12
|
-
* export const { getSessionToken } = createServerAccess({ cookies });
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* // app/actions/profile.ts
|
|
17
|
-
* "use server";
|
|
18
|
-
* import { getSessionToken } from "@/lib/access-server";
|
|
19
|
-
*
|
|
20
|
-
* export async function getProfile() {
|
|
21
|
-
* const token = await getSessionToken();
|
|
22
|
-
* if (!token) throw new Error("Not authenticated");
|
|
23
|
-
*
|
|
24
|
-
* const res = await fetch("https://api.myapp.com/v1/users/auth/me", {
|
|
25
|
-
* headers: { Authorization: `Bearer ${token}` },
|
|
26
|
-
* });
|
|
27
|
-
* return res.json();
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @packageDocumentation
|
|
32
|
-
*/
|
|
33
|
-
/** Minimal cookie store interface (subset of Next.js ReadonlyRequestCookies) */
|
|
34
|
-
interface CookieStore {
|
|
35
|
-
get(name: string): {
|
|
36
|
-
value: string;
|
|
37
|
-
} | undefined;
|
|
38
|
-
}
|
|
39
|
-
/** The `cookies` function from `next/headers` */
|
|
40
|
-
type CookiesFn = () => CookieStore | Promise<CookieStore>;
|
|
41
|
-
interface ServerAccessOptions {
|
|
42
|
-
/**
|
|
43
|
-
* The `cookies` function imported from `next/headers`.
|
|
44
|
-
* Required — pass it explicitly to avoid bundler issues with dynamic imports.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* import { cookies } from "next/headers";
|
|
49
|
-
* createServerAccess({ cookies });
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
cookies: CookiesFn;
|
|
53
|
-
/**
|
|
54
|
-
* Name of the httpOnly cookie that carries the access token.
|
|
55
|
-
* Must match the cookie set by the Azirid API.
|
|
56
|
-
* @default "__session"
|
|
57
|
-
*/
|
|
58
|
-
cookieName?: string;
|
|
59
|
-
}
|
|
60
|
-
interface ServerAccess {
|
|
61
|
-
/**
|
|
62
|
-
* Read the raw JWT access token from the session cookie.
|
|
63
|
-
* Returns `null` when no cookie is present or when called
|
|
64
|
-
* outside a Next.js server context.
|
|
65
|
-
*/
|
|
66
|
-
getSessionToken: () => Promise<string | null>;
|
|
67
|
-
/** Alias for {@link getSessionToken}. */
|
|
68
|
-
getAccessToken: () => Promise<string | null>;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Create server-side helpers bound to the session cookie.
|
|
72
|
-
*
|
|
73
|
-
* Call once at module scope, then use the returned functions
|
|
74
|
-
* in any Server Component, Server Action, or Route Handler.
|
|
75
|
-
*/
|
|
76
|
-
declare function createServerAccess(options: ServerAccessOptions): ServerAccess;
|
|
77
|
-
interface SessionSyncOptions {
|
|
78
|
-
/** Cookie name (default: "__session") */
|
|
79
|
-
cookieName?: string;
|
|
80
|
-
/** Set Secure flag on cookie (default: false) */
|
|
81
|
-
secure?: boolean;
|
|
82
|
-
/** Cookie max age in seconds (default: 3600 = 1h) */
|
|
83
|
-
maxAge?: number;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Create a route handler that syncs the access token to a local httpOnly cookie.
|
|
87
|
-
*
|
|
88
|
-
* Use this in a Next.js App Router route to bridge cross-origin sessions:
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* // app/api/auth/session/route.ts
|
|
93
|
-
* import { createSessionSyncHandler } from "azirid-react/server";
|
|
94
|
-
* export const { POST, DELETE } = createSessionSyncHandler();
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
declare function createSessionSyncHandler(options?: SessionSyncOptions): {
|
|
98
|
-
POST(req: Request): Promise<Response>;
|
|
99
|
-
DELETE(): Promise<Response>;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export { type ServerAccess, type ServerAccessOptions, type SessionSyncOptions, createServerAccess, createSessionSyncHandler };
|