@civic/auth 0.0.1-beta.2 → 0.0.1-beta.20

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.
Files changed (84) hide show
  1. package/README.md +26 -0
  2. package/dist/AuthProvider-Bj_Prt1x.d.ts +21 -0
  3. package/dist/AuthProvider-DUAoX4G9.d.mts +21 -0
  4. package/dist/UserProvider-CMLaYOUD.d.ts +16 -0
  5. package/dist/UserProvider-Cbm8MZkJ.d.mts +16 -0
  6. package/dist/chunk-5UQQYXCX.js +1 -0
  7. package/dist/chunk-5UQQYXCX.js.map +1 -0
  8. package/dist/chunk-BFESCRFK.mjs +118 -0
  9. package/dist/chunk-BFESCRFK.mjs.map +1 -0
  10. package/dist/chunk-CBQ3HKRV.mjs +599 -0
  11. package/dist/chunk-CBQ3HKRV.mjs.map +1 -0
  12. package/dist/chunk-CRTRMMJ7.js.map +1 -1
  13. package/dist/chunk-CZ3AVCKD.js +171 -0
  14. package/dist/chunk-CZ3AVCKD.js.map +1 -0
  15. package/dist/chunk-DJFTZS4P.js +118 -0
  16. package/dist/chunk-DJFTZS4P.js.map +1 -0
  17. package/dist/chunk-HTTTZ2BP.mjs +223 -0
  18. package/dist/chunk-HTTTZ2BP.mjs.map +1 -0
  19. package/dist/chunk-O2SODTR3.js +599 -0
  20. package/dist/chunk-O2SODTR3.js.map +1 -0
  21. package/dist/chunk-O6DPCPRH.js +223 -0
  22. package/dist/chunk-O6DPCPRH.js.map +1 -0
  23. package/dist/chunk-PMJAV4JJ.mjs +1 -0
  24. package/dist/chunk-PMJAV4JJ.mjs.map +1 -0
  25. package/dist/chunk-UADVRCHY.mjs +710 -0
  26. package/dist/chunk-UADVRCHY.mjs.map +1 -0
  27. package/dist/chunk-VJVRFKDH.js +710 -0
  28. package/dist/chunk-VJVRFKDH.js.map +1 -0
  29. package/dist/chunk-X3FQBE22.mjs +171 -0
  30. package/dist/chunk-X3FQBE22.mjs.map +1 -0
  31. package/dist/index.css +63 -70
  32. package/dist/index.css.map +1 -1
  33. package/dist/index.d.mts +3 -1
  34. package/dist/index.d.ts +3 -1
  35. package/dist/index.js +2 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +1 -0
  38. package/dist/nextjs/client.css +335 -0
  39. package/dist/nextjs/client.css.map +1 -0
  40. package/dist/nextjs/client.d.mts +12 -0
  41. package/dist/nextjs/client.d.ts +12 -0
  42. package/dist/nextjs/client.js +179 -0
  43. package/dist/nextjs/client.js.map +1 -0
  44. package/dist/nextjs/client.mjs +179 -0
  45. package/dist/nextjs/client.mjs.map +1 -0
  46. package/dist/nextjs.d.mts +67 -15
  47. package/dist/nextjs.d.ts +67 -15
  48. package/dist/nextjs.js +158 -180
  49. package/dist/nextjs.js.map +1 -1
  50. package/dist/nextjs.mjs +155 -177
  51. package/dist/nextjs.mjs.map +1 -1
  52. package/dist/react.d.mts +31 -81
  53. package/dist/react.d.ts +31 -81
  54. package/dist/react.js +35 -634
  55. package/dist/react.js.map +1 -1
  56. package/dist/react.mjs +65 -664
  57. package/dist/react.mjs.map +1 -1
  58. package/dist/server.d.mts +14 -34
  59. package/dist/server.d.ts +14 -34
  60. package/dist/server.js +4 -185
  61. package/dist/server.js.map +1 -1
  62. package/dist/server.mjs +10 -191
  63. package/dist/server.mjs.map +1 -1
  64. package/dist/storage-B2eAQNdv.d.ts +25 -0
  65. package/dist/storage-BJPUpxhm.d.mts +25 -0
  66. package/dist/types-Bqm9OCZN.d.mts +22 -0
  67. package/dist/types-Bqm9OCZN.d.ts +22 -0
  68. package/dist/types-HdCjGldB.d.mts +58 -0
  69. package/dist/types-HdCjGldB.d.ts +58 -0
  70. package/package.json +26 -17
  71. package/dist/chunk-5NUJ7LFF.mjs +0 -17
  72. package/dist/chunk-5NUJ7LFF.mjs.map +0 -1
  73. package/dist/chunk-KS7ERXGZ.js +0 -481
  74. package/dist/chunk-KS7ERXGZ.js.map +0 -1
  75. package/dist/chunk-NINRO7GS.js +0 -209
  76. package/dist/chunk-NINRO7GS.js.map +0 -1
  77. package/dist/chunk-NXBKSUKI.mjs +0 -481
  78. package/dist/chunk-NXBKSUKI.mjs.map +0 -1
  79. package/dist/chunk-T7HUHQ3J.mjs +0 -209
  80. package/dist/chunk-T7HUHQ3J.mjs.map +0 -1
  81. package/dist/chunk-WZLC5B4C.js +0 -17
  82. package/dist/chunk-WZLC5B4C.js.map +0 -1
  83. package/dist/index-DoDoIY_K.d.mts +0 -79
  84. package/dist/index-DoDoIY_K.d.ts +0 -79
@@ -0,0 +1,179 @@
1
+ import "../chunk-PMJAV4JJ.mjs";
2
+ import {
3
+ AuthProvider,
4
+ UserProvider
5
+ } from "../chunk-UADVRCHY.mjs";
6
+ import {
7
+ NextjsClientStorage,
8
+ resolveCallbackUrl
9
+ } from "../chunk-BFESCRFK.mjs";
10
+ import {
11
+ resolveAuthConfig
12
+ } from "../chunk-X3FQBE22.mjs";
13
+ import "../chunk-HTTTZ2BP.mjs";
14
+ import {
15
+ ConfidentialClientPKCEConsumer
16
+ } from "../chunk-CBQ3HKRV.mjs";
17
+ import {
18
+ __async,
19
+ __objRest,
20
+ __spreadProps,
21
+ __spreadValues
22
+ } from "../chunk-RGHW4PYM.mjs";
23
+
24
+ // src/nextjs/providers/NextAuthProvider.tsx
25
+ import { useEffect as useEffect3, useState } from "react";
26
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
27
+
28
+ // src/nextjs/hooks/useUserCookie.ts
29
+ import { useEffect, useRef } from "react";
30
+ import { useRouter } from "next/navigation.js";
31
+ import { useQuery } from "@tanstack/react-query";
32
+
33
+ // src/lib/cookies.ts
34
+ var getWindowCookieValue = ({
35
+ key,
36
+ window: window2,
37
+ parseJson = false
38
+ }) => {
39
+ const cookie = window2.document.cookie;
40
+ if (!cookie) return null;
41
+ const cookies = cookie.split(";");
42
+ for (const c of cookies) {
43
+ const [name, value] = c.trim().split("=");
44
+ if (value && name === key) {
45
+ try {
46
+ const decodeURIComponentValue = decodeURIComponent(value);
47
+ return parseJson === true ? JSON.parse(decodeURIComponentValue) : decodeURIComponentValue;
48
+ } catch (e) {
49
+ return value;
50
+ }
51
+ }
52
+ }
53
+ return null;
54
+ };
55
+
56
+ // src/nextjs/hooks/useUserCookie.ts
57
+ var getUserFromCookie = () => {
58
+ const userCookie = getWindowCookieValue({
59
+ key: "user" /* USER */,
60
+ window: globalThis.window,
61
+ parseJson: true
62
+ });
63
+ return userCookie;
64
+ };
65
+ var useUserCookie = () => {
66
+ const hasRunRef = useRef(false);
67
+ const router = useRouter();
68
+ const { data: user } = useQuery({
69
+ queryKey: ["user"],
70
+ queryFn: () => getUserFromCookie(),
71
+ refetchInterval: 2e3,
72
+ refetchIntervalInBackground: true,
73
+ enabled: !hasRunRef.current,
74
+ refetchOnWindowFocus: true
75
+ });
76
+ useEffect(() => {
77
+ if (user) {
78
+ if (!hasRunRef.current) {
79
+ hasRunRef.current = true;
80
+ router.refresh();
81
+ }
82
+ } else {
83
+ hasRunRef.current = false;
84
+ }
85
+ }, [user, router]);
86
+ return user != null ? user : null;
87
+ };
88
+
89
+ // src/nextjs/hooks/useTokenCookie.ts
90
+ import { useEffect as useEffect2, useRef as useRef2 } from "react";
91
+ import { useRouter as useRouter2 } from "next/navigation.js";
92
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
93
+ var getTokenFromCookie = (tokenName) => {
94
+ return getWindowCookieValue({
95
+ key: tokenName,
96
+ window: globalThis.window,
97
+ parseJson: false
98
+ });
99
+ };
100
+ var useTokenCookie = (tokenName) => {
101
+ const hasRunRef = useRef2(false);
102
+ const router = useRouter2();
103
+ const { data: token } = useQuery2({
104
+ queryKey: ["token", tokenName],
105
+ queryFn: () => getTokenFromCookie(tokenName) || null,
106
+ refetchInterval: 2e3,
107
+ refetchIntervalInBackground: true,
108
+ enabled: !hasRunRef.current,
109
+ refetchOnWindowFocus: true
110
+ });
111
+ useEffect2(() => {
112
+ if (token) {
113
+ if (!hasRunRef.current) {
114
+ hasRunRef.current = true;
115
+ router.refresh();
116
+ }
117
+ } else {
118
+ hasRunRef.current = false;
119
+ }
120
+ }, [token, router]);
121
+ return token != null ? token : null;
122
+ };
123
+
124
+ // src/nextjs/providers/NextAuthProvider.tsx
125
+ import { jsx } from "react/jsx-runtime";
126
+ var queryClient = new QueryClient();
127
+ var CivicNextAuthProvider = (_a) => {
128
+ var _b = _a, {
129
+ children
130
+ } = _b, props = __objRest(_b, [
131
+ "children"
132
+ ]);
133
+ const [redirectUrl, setRedirectUrl] = useState("");
134
+ const resolvedConfig = resolveAuthConfig();
135
+ const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } = resolvedConfig;
136
+ useEffect3(() => {
137
+ if (typeof globalThis.window !== "undefined") {
138
+ const currentUrl = globalThis.window.location.href;
139
+ setRedirectUrl(resolveCallbackUrl(resolvedConfig, currentUrl));
140
+ }
141
+ }, [callbackUrl, resolvedConfig]);
142
+ const user = useUserCookie();
143
+ const idToken = useTokenCookie("id_token" /* ID_TOKEN */);
144
+ const combinedUser = user ? __spreadProps(__spreadValues({}, user || {}), { idToken }) : null;
145
+ const sessionData = __spreadValues({
146
+ authenticated: !!user
147
+ }, idToken ? { idToken } : {});
148
+ const signOut = () => __async(void 0, null, function* () {
149
+ if (props.onSignOut) {
150
+ yield props.onSignOut();
151
+ }
152
+ window.location.href = logoutUrl;
153
+ return;
154
+ });
155
+ return /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(
156
+ AuthProvider,
157
+ __spreadProps(__spreadValues({}, props), {
158
+ redirectUrl,
159
+ config: { oauthServer },
160
+ clientId,
161
+ pkceConsumer: new ConfidentialClientPKCEConsumer(challengeUrl),
162
+ sessionData,
163
+ children: /* @__PURE__ */ jsx(
164
+ UserProvider,
165
+ {
166
+ storage: new NextjsClientStorage(),
167
+ user: combinedUser,
168
+ signOut,
169
+ children
170
+ }
171
+ )
172
+ })
173
+ ) });
174
+ };
175
+ export {
176
+ CivicNextAuthProvider as CivicAuthProvider,
177
+ useUserCookie
178
+ };
179
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/nextjs/providers/NextAuthProvider.tsx","../../src/nextjs/hooks/useUserCookie.ts","../../src/lib/cookies.ts","../../src/nextjs/hooks/useTokenCookie.ts"],"sourcesContent":["\"use client\";\n/**\n * A very small context provider for the user object - it takes the user object from the cookie and provides it to the app.\n */\nimport { useEffect, useState } from \"react\";\nimport { AuthProvider, AuthProviderProps } from \"@/shared/AuthProvider.js\";\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\nimport { resolveAuthConfig } from \"@/nextjs/config.js\";\nimport { resolveCallbackUrl } from \"@/nextjs/utils.js\";\n\n// adding the styles import here to be added to the bundle\nimport \"@/styles.css\";\nimport { ConfidentialClientPKCEConsumer } from \"@/services/PKCE.js\";\nimport { NextjsClientStorage } from \"@/nextjs/cookies\";\nimport { UserProvider } from \"@/shared/UserProvider\";\nimport { useUserCookie } from \"../hooks/useUserCookie\";\nimport { OAuthTokens } from \"@/shared/types\";\nimport { useTokenCookie } from \"../hooks/useTokenCookie\";\nimport { User } from \"@/types\";\n\nconst queryClient = new QueryClient();\n\nexport type NextCivicAuthProviderProps = Omit<AuthProviderProps, \"clientId\">;\n\nexport const CivicNextAuthProvider = ({\n children,\n ...props\n}: NextCivicAuthProviderProps) => {\n const [redirectUrl, setRedirectUrl] = useState<string>(\"\");\n const resolvedConfig = resolveAuthConfig();\n const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } =\n resolvedConfig;\n\n useEffect(() => {\n if (typeof globalThis.window !== \"undefined\") {\n const currentUrl = globalThis.window.location.href;\n setRedirectUrl(resolveCallbackUrl(resolvedConfig, currentUrl));\n }\n }, [callbackUrl, resolvedConfig]);\n\n const user = useUserCookie();\n const idToken = useTokenCookie(OAuthTokens.ID_TOKEN);\n const combinedUser = user ? ({ ...(user || {}), idToken } as User) : null;\n const sessionData = {\n authenticated: !!user,\n ...(idToken ? { idToken } : {}),\n };\n const signOut = async (): Promise<void> => {\n if (props.onSignOut) {\n await props.onSignOut();\n }\n window.location.href = logoutUrl;\n return;\n };\n return (\n <QueryClientProvider client={queryClient}>\n <AuthProvider\n {...props}\n redirectUrl={redirectUrl}\n config={{ oauthServer }}\n clientId={clientId}\n pkceConsumer={new ConfidentialClientPKCEConsumer(challengeUrl)}\n sessionData={sessionData}\n >\n <UserProvider\n storage={new NextjsClientStorage()}\n user={combinedUser}\n signOut={signOut}\n >\n {children}\n </UserProvider>\n </AuthProvider>\n </QueryClientProvider>\n );\n};\n","\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { useRouter } from \"next/navigation.js\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { getWindowCookieValue } from \"@/lib/cookies.js\";\nimport { EmptyObject, User } from \"@/types\";\nimport { UserStorage } from \"@/shared/types\";\n\nconst getUserFromCookie = () => {\n const userCookie = getWindowCookieValue({\n key: UserStorage.USER,\n window: globalThis.window,\n parseJson: true,\n });\n return userCookie;\n};\n\nexport const useUserCookie = <T extends EmptyObject>() => {\n const hasRunRef = useRef(false);\n const router = useRouter();\n\n const { data: user } = useQuery({\n queryKey: [\"user\"],\n queryFn: () => getUserFromCookie() as User<T> | null,\n refetchInterval: 2000,\n refetchIntervalInBackground: true,\n enabled: !hasRunRef.current,\n refetchOnWindowFocus: true,\n });\n\n useEffect(() => {\n if (user) {\n if (!hasRunRef.current) {\n hasRunRef.current = true;\n router.refresh();\n }\n } else {\n hasRunRef.current = false;\n }\n }, [user, router]);\n\n return user ?? null;\n};\n","const getWindowCookieValue = ({\n key,\n window,\n parseJson = false,\n}: {\n key: string;\n window: Window;\n parseJson?: boolean;\n}) => {\n const cookie = window.document.cookie;\n if (!cookie) return null;\n const cookies = cookie.split(\";\");\n for (const c of cookies) {\n const [name, value] = c.trim().split(\"=\");\n if (value && name === key) {\n try {\n const decodeURIComponentValue = decodeURIComponent(value);\n return parseJson === true\n ? JSON.parse(decodeURIComponentValue)\n : decodeURIComponentValue;\n } catch {\n return value;\n }\n }\n }\n return null;\n};\nexport { getWindowCookieValue };\n","\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { useRouter } from \"next/navigation.js\";\nimport { useQuery } from \"@tanstack/react-query\";\nimport { getWindowCookieValue } from \"@/lib/cookies.js\";\nimport { OAuthTokens } from \"@/shared/types\";\n\nconst getTokenFromCookie = (tokenName: OAuthTokens): string => {\n return getWindowCookieValue({\n key: tokenName,\n window: globalThis.window,\n parseJson: false,\n });\n};\n\nexport const useTokenCookie = (tokenName: OAuthTokens): string | null => {\n const hasRunRef = useRef(false);\n const router = useRouter();\n\n const { data: token } = useQuery({\n queryKey: [\"token\", tokenName],\n queryFn: () => getTokenFromCookie(tokenName) || null,\n refetchInterval: 2000,\n refetchIntervalInBackground: true,\n enabled: !hasRunRef.current,\n refetchOnWindowFocus: true,\n });\n\n useEffect(() => {\n if (token) {\n if (!hasRunRef.current) {\n hasRunRef.current = true;\n router.refresh();\n }\n } else {\n hasRunRef.current = false;\n }\n }, [token, router]);\n\n return token ?? null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAAS,aAAAA,YAAW,gBAAgB;AAEpC,SAAS,aAAa,2BAA2B;;;ACLjD,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;;;ACHzB,IAAM,uBAAuB,CAAC;AAAA,EAC5B;AAAA,EACA,QAAAC;AAAA,EACA,YAAY;AACd,MAIM;AACJ,QAAM,SAASA,QAAO,SAAS;AAC/B,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,UAAU,OAAO,MAAM,GAAG;AAChC,aAAW,KAAK,SAAS;AACvB,UAAM,CAAC,MAAM,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG;AACxC,QAAI,SAAS,SAAS,KAAK;AACzB,UAAI;AACF,cAAM,0BAA0B,mBAAmB,KAAK;AACxD,eAAO,cAAc,OACjB,KAAK,MAAM,uBAAuB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AAAA,MACA,QAAQ,EAAE,YAAY;AAAA,MACtB;AAAA,MACA,cAAc,IAAI,+BAA+B,YAAY;AAAA,MAC7D;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,SAAS,IAAI,oBAAoB;AAAA,UACjC,MAAM;AAAA,UACN;AAAA,UAEC;AAAA;AAAA,MACH;AAAA;AAAA,EACF,GACF;AAEJ;","names":["useEffect","window","useEffect","useRef","useRouter","useQuery","useRef","useRouter","useQuery","useEffect","useEffect"]}
package/dist/nextjs.d.mts CHANGED
@@ -2,33 +2,55 @@ import * as next_dist_shared_lib_image_config from 'next/dist/shared/lib/image-c
2
2
  import * as next_dist_lib_load_custom_routes from 'next/dist/lib/load-custom-routes';
3
3
  import * as next_dist_server_config_shared from 'next/dist/server/config-shared';
4
4
  import { NextConfig } from 'next';
5
- import { U as User, a as UnknownObject } from './index-DoDoIY_K.mjs';
5
+ import { T as TokensCookieConfig, a as CookieConfig, O as OAuthTokens, C as CodeVerifier } from './types-Bqm9OCZN.mjs';
6
+ import { U as User, S as SessionData, a as UnknownObject } from './types-HdCjGldB.mjs';
6
7
  import { NextRequest, NextResponse } from 'next/server.js';
8
+ import { NextResponse as NextResponse$1 } from 'next/server';
9
+ import { C as CookieStorage, a as CookieStorageSettings } from './storage-BJPUpxhm.mjs';
7
10
  import 'oslo/oauth2';
8
- import 'oslo/jwt';
9
11
 
10
- interface CookieConfig {
11
- secure?: boolean;
12
- sameSite?: "strict" | "lax" | "none";
13
- domain?: string;
14
- path?: string;
15
- maxAge?: number;
16
- }
12
+ type CookiesConfigObject = {
13
+ tokens: TokensCookieConfig;
14
+ user: CookieConfig;
15
+ };
17
16
  type AuthConfigWithDefaults = {
18
17
  clientId: string;
19
18
  oauthServer: string;
20
19
  callbackUrl: string;
21
20
  loginUrl: string;
22
21
  logoutUrl: string;
22
+ appUrl?: string;
23
23
  challengeUrl: string;
24
24
  include: string[];
25
25
  exclude: string[];
26
- cookies: {
27
- tokens: CookieConfig;
28
- user: CookieConfig;
29
- };
26
+ cookies: CookiesConfigObject;
30
27
  };
31
28
  type AuthConfig = Partial<AuthConfigWithDefaults>;
29
+ type DefinedAuthConfig = AuthConfigWithDefaults;
30
+ /**
31
+ * Default configuration values that will be used if not overridden
32
+ */
33
+ declare const defaultAuthConfig: Omit<AuthConfigWithDefaults, "clientId">;
34
+ /**
35
+ * Resolves the authentication configuration by combining:
36
+ * 1. Default values
37
+ * 2. Environment variables (set internally by the plugin)
38
+ * 3. Explicitly passed configuration
39
+ *
40
+ * Note: Developers should not set _civic_auth_* environment variables directly.
41
+ * Instead, pass configuration to the createCivicAuthPlugin in next.config.js:
42
+ *
43
+ * @example
44
+ * ```js
45
+ * // next.config.js
46
+ * export default createCivicAuthPlugin({
47
+ * callbackUrl: '/custom/callback',
48
+ * })
49
+ * ```
50
+ */
51
+ declare const resolveAuthConfig: (config?: AuthConfig) => AuthConfigWithDefaults & {
52
+ clientId: string;
53
+ };
32
54
  /**
33
55
  * Creates a Next.js plugin that handles auth configuration.
34
56
  *
@@ -60,6 +82,7 @@ declare const createCivicAuthPlugin: (clientId: string, authConfig?: AuthConfig)
60
82
  _civic_auth_challenge_url: string;
61
83
  _civic_auth_login_url: string;
62
84
  _civic_auth_logout_url: string;
85
+ _civic_auth_app_url: string | undefined;
63
86
  _civic_auth_includes: string;
64
87
  _civic_auth_excludes: string;
65
88
  _civic_auth_cookie_config: string;
@@ -166,7 +189,11 @@ declare const createCivicAuthPlugin: (clientId: string, authConfig?: AuthConfig)
166
189
  experimental?: next_dist_server_config_shared.ExperimentalConfig;
167
190
  };
168
191
 
169
- declare const getUser: () => User<UnknownObject> | null;
192
+ /**
193
+ * Used on the server-side to get the user object from the cookie
194
+ */
195
+
196
+ declare const getUser: () => User | null;
170
197
 
171
198
  type Middleware = (request: NextRequest) => Promise<NextResponse> | NextResponse;
172
199
  /**
@@ -216,4 +243,29 @@ declare function auth(authConfig?: AuthConfig): (middleware: Middleware) => ((re
216
243
  */
217
244
  declare const handler: (authConfig?: {}) => (request: NextRequest) => Promise<NextResponse>;
218
245
 
219
- export { auth, authMiddleware, createCivicAuthPlugin, getUser, handler, withAuth };
246
+ /**
247
+ * Creates HTTP-only cookies for authentication tokens
248
+ */
249
+ declare const createTokenCookies: (response: NextResponse$1, sessionData: SessionData, config: AuthConfig) => void;
250
+ /**
251
+ * Creates a client-readable cookie with user info
252
+ */
253
+ declare const createUserInfoCookie: (response: NextResponse$1, user: User<UnknownObject> | null, sessionData: SessionData, config: AuthConfig) => void;
254
+ /**
255
+ * Clears all authentication cookies
256
+ */
257
+ declare const clearAuthCookies: (config: AuthConfig) => Promise<void>;
258
+ type KeySetter = OAuthTokens | CodeVerifier;
259
+ declare class NextjsCookieStorage extends CookieStorage {
260
+ readonly config: Partial<TokensCookieConfig>;
261
+ constructor(config?: Partial<TokensCookieConfig>);
262
+ get(key: string): string | null;
263
+ set(key: KeySetter, value: string): void;
264
+ }
265
+ declare class NextjsClientStorage extends CookieStorage {
266
+ constructor(config?: Partial<CookieStorageSettings>);
267
+ get(key: string): string | null;
268
+ set(key: string, value: string): void;
269
+ }
270
+
271
+ export { type AuthConfig, type AuthConfigWithDefaults, type CookiesConfigObject, type DefinedAuthConfig, NextjsClientStorage, NextjsCookieStorage, auth, authMiddleware, clearAuthCookies, createCivicAuthPlugin, createTokenCookies, createUserInfoCookie, defaultAuthConfig, getUser, handler, resolveAuthConfig, withAuth };
package/dist/nextjs.d.ts CHANGED
@@ -2,33 +2,55 @@ import * as next_dist_shared_lib_image_config from 'next/dist/shared/lib/image-c
2
2
  import * as next_dist_lib_load_custom_routes from 'next/dist/lib/load-custom-routes';
3
3
  import * as next_dist_server_config_shared from 'next/dist/server/config-shared';
4
4
  import { NextConfig } from 'next';
5
- import { U as User, a as UnknownObject } from './index-DoDoIY_K.js';
5
+ import { T as TokensCookieConfig, a as CookieConfig, O as OAuthTokens, C as CodeVerifier } from './types-Bqm9OCZN.js';
6
+ import { U as User, S as SessionData, a as UnknownObject } from './types-HdCjGldB.js';
6
7
  import { NextRequest, NextResponse } from 'next/server.js';
8
+ import { NextResponse as NextResponse$1 } from 'next/server';
9
+ import { C as CookieStorage, a as CookieStorageSettings } from './storage-B2eAQNdv.js';
7
10
  import 'oslo/oauth2';
8
- import 'oslo/jwt';
9
11
 
10
- interface CookieConfig {
11
- secure?: boolean;
12
- sameSite?: "strict" | "lax" | "none";
13
- domain?: string;
14
- path?: string;
15
- maxAge?: number;
16
- }
12
+ type CookiesConfigObject = {
13
+ tokens: TokensCookieConfig;
14
+ user: CookieConfig;
15
+ };
17
16
  type AuthConfigWithDefaults = {
18
17
  clientId: string;
19
18
  oauthServer: string;
20
19
  callbackUrl: string;
21
20
  loginUrl: string;
22
21
  logoutUrl: string;
22
+ appUrl?: string;
23
23
  challengeUrl: string;
24
24
  include: string[];
25
25
  exclude: string[];
26
- cookies: {
27
- tokens: CookieConfig;
28
- user: CookieConfig;
29
- };
26
+ cookies: CookiesConfigObject;
30
27
  };
31
28
  type AuthConfig = Partial<AuthConfigWithDefaults>;
29
+ type DefinedAuthConfig = AuthConfigWithDefaults;
30
+ /**
31
+ * Default configuration values that will be used if not overridden
32
+ */
33
+ declare const defaultAuthConfig: Omit<AuthConfigWithDefaults, "clientId">;
34
+ /**
35
+ * Resolves the authentication configuration by combining:
36
+ * 1. Default values
37
+ * 2. Environment variables (set internally by the plugin)
38
+ * 3. Explicitly passed configuration
39
+ *
40
+ * Note: Developers should not set _civic_auth_* environment variables directly.
41
+ * Instead, pass configuration to the createCivicAuthPlugin in next.config.js:
42
+ *
43
+ * @example
44
+ * ```js
45
+ * // next.config.js
46
+ * export default createCivicAuthPlugin({
47
+ * callbackUrl: '/custom/callback',
48
+ * })
49
+ * ```
50
+ */
51
+ declare const resolveAuthConfig: (config?: AuthConfig) => AuthConfigWithDefaults & {
52
+ clientId: string;
53
+ };
32
54
  /**
33
55
  * Creates a Next.js plugin that handles auth configuration.
34
56
  *
@@ -60,6 +82,7 @@ declare const createCivicAuthPlugin: (clientId: string, authConfig?: AuthConfig)
60
82
  _civic_auth_challenge_url: string;
61
83
  _civic_auth_login_url: string;
62
84
  _civic_auth_logout_url: string;
85
+ _civic_auth_app_url: string | undefined;
63
86
  _civic_auth_includes: string;
64
87
  _civic_auth_excludes: string;
65
88
  _civic_auth_cookie_config: string;
@@ -166,7 +189,11 @@ declare const createCivicAuthPlugin: (clientId: string, authConfig?: AuthConfig)
166
189
  experimental?: next_dist_server_config_shared.ExperimentalConfig;
167
190
  };
168
191
 
169
- declare const getUser: () => User<UnknownObject> | null;
192
+ /**
193
+ * Used on the server-side to get the user object from the cookie
194
+ */
195
+
196
+ declare const getUser: () => User | null;
170
197
 
171
198
  type Middleware = (request: NextRequest) => Promise<NextResponse> | NextResponse;
172
199
  /**
@@ -216,4 +243,29 @@ declare function auth(authConfig?: AuthConfig): (middleware: Middleware) => ((re
216
243
  */
217
244
  declare const handler: (authConfig?: {}) => (request: NextRequest) => Promise<NextResponse>;
218
245
 
219
- export { auth, authMiddleware, createCivicAuthPlugin, getUser, handler, withAuth };
246
+ /**
247
+ * Creates HTTP-only cookies for authentication tokens
248
+ */
249
+ declare const createTokenCookies: (response: NextResponse$1, sessionData: SessionData, config: AuthConfig) => void;
250
+ /**
251
+ * Creates a client-readable cookie with user info
252
+ */
253
+ declare const createUserInfoCookie: (response: NextResponse$1, user: User<UnknownObject> | null, sessionData: SessionData, config: AuthConfig) => void;
254
+ /**
255
+ * Clears all authentication cookies
256
+ */
257
+ declare const clearAuthCookies: (config: AuthConfig) => Promise<void>;
258
+ type KeySetter = OAuthTokens | CodeVerifier;
259
+ declare class NextjsCookieStorage extends CookieStorage {
260
+ readonly config: Partial<TokensCookieConfig>;
261
+ constructor(config?: Partial<TokensCookieConfig>);
262
+ get(key: string): string | null;
263
+ set(key: KeySetter, value: string): void;
264
+ }
265
+ declare class NextjsClientStorage extends CookieStorage {
266
+ constructor(config?: Partial<CookieStorageSettings>);
267
+ get(key: string): string | null;
268
+ set(key: string, value: string): void;
269
+ }
270
+
271
+ export { type AuthConfig, type AuthConfigWithDefaults, type CookiesConfigObject, type DefinedAuthConfig, NextjsClientStorage, NextjsCookieStorage, auth, authMiddleware, clearAuthCookies, createCivicAuthPlugin, createTokenCookies, createUserInfoCookie, defaultAuthConfig, getUser, handler, resolveAuthConfig, withAuth };