@civic/auth 0.0.1-beta.17 → 0.0.1-beta.19
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/dist/AuthProvider-Bj_Prt1x.d.ts +21 -0
- package/dist/AuthProvider-DUAoX4G9.d.mts +21 -0
- package/dist/{index-DTimUlkB.d.ts → UserProvider-CMLaYOUD.d.ts} +1 -2
- package/dist/{index-DvjkKpkk.d.mts → UserProvider-Cbm8MZkJ.d.mts} +1 -2
- package/dist/chunk-5UQQYXCX.js +1 -0
- package/dist/chunk-5UQQYXCX.js.map +1 -0
- package/dist/chunk-BFESCRFK.mjs +118 -0
- package/dist/chunk-BFESCRFK.mjs.map +1 -0
- package/dist/{chunk-G3P5TIO2.mjs → chunk-CBQ3HKRV.mjs} +123 -232
- package/dist/chunk-CBQ3HKRV.mjs.map +1 -0
- package/dist/{chunk-SEKF2WZX.js → chunk-CZ3AVCKD.js} +16 -71
- package/dist/chunk-CZ3AVCKD.js.map +1 -0
- package/dist/chunk-DJFTZS4P.js +118 -0
- package/dist/chunk-DJFTZS4P.js.map +1 -0
- package/dist/chunk-HTTTZ2BP.mjs +223 -0
- package/dist/chunk-HTTTZ2BP.mjs.map +1 -0
- package/dist/{chunk-RF23Q4V6.js → chunk-O2SODTR3.js} +114 -223
- package/dist/chunk-O2SODTR3.js.map +1 -0
- package/dist/chunk-O6DPCPRH.js +223 -0
- package/dist/chunk-O6DPCPRH.js.map +1 -0
- package/dist/chunk-PMJAV4JJ.mjs +1 -0
- package/dist/chunk-PMJAV4JJ.mjs.map +1 -0
- package/dist/chunk-UADVRCHY.mjs +710 -0
- package/dist/chunk-UADVRCHY.mjs.map +1 -0
- package/dist/chunk-VJVRFKDH.js +710 -0
- package/dist/chunk-VJVRFKDH.js.map +1 -0
- package/dist/{chunk-5XL2ST72.mjs → chunk-X3FQBE22.mjs} +15 -70
- package/dist/chunk-X3FQBE22.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/nextjs/client.css +335 -0
- package/dist/nextjs/client.css.map +1 -0
- package/dist/nextjs/client.d.mts +12 -0
- package/dist/nextjs/client.d.ts +12 -0
- package/dist/nextjs/client.js +179 -0
- package/dist/nextjs/client.js.map +1 -0
- package/dist/nextjs/client.mjs +179 -0
- package/dist/nextjs/client.mjs.map +1 -0
- package/dist/nextjs.d.mts +35 -7
- package/dist/nextjs.d.ts +35 -7
- package/dist/nextjs.js +130 -43
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.mjs +117 -30
- package/dist/nextjs.mjs.map +1 -1
- package/dist/react.d.mts +7 -31
- package/dist/react.d.ts +7 -31
- package/dist/react.js +15 -835
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +47 -867
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -24
- package/dist/server.d.ts +3 -24
- package/dist/server.js +4 -2
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +4 -2
- package/dist/storage-B2eAQNdv.d.ts +25 -0
- package/dist/storage-BJPUpxhm.d.mts +25 -0
- package/dist/{types-b4c1koXj.d.mts → types-Bqm9OCZN.d.mts} +5 -2
- package/dist/{types-b4c1koXj.d.ts → types-Bqm9OCZN.d.ts} +5 -2
- package/package.json +11 -2
- package/dist/chunk-5XL2ST72.mjs.map +0 -1
- package/dist/chunk-G3P5TIO2.mjs.map +0 -1
- package/dist/chunk-RF23Q4V6.js.map +0 -1
- package/dist/chunk-SEKF2WZX.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { A as AuthProviderProps } from '../AuthProvider-Bj_Prt1x.js';
|
|
3
|
+
import { b as EmptyObject, U as User } from '../types-HdCjGldB.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'oslo/oauth2';
|
|
6
|
+
|
|
7
|
+
type NextCivicAuthProviderProps = Omit<AuthProviderProps, "clientId">;
|
|
8
|
+
declare const CivicNextAuthProvider: ({ children, ...props }: NextCivicAuthProviderProps) => react_jsx_runtime.JSX.Element;
|
|
9
|
+
|
|
10
|
+
declare const useUserCookie: <T extends EmptyObject>() => User<T> | null;
|
|
11
|
+
|
|
12
|
+
export { type NextCivicAuthProviderProps as AuthProviderProps, CivicNextAuthProvider as CivicAuthProvider, useUserCookie };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-5UQQYXCX.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkVJVRFKDHjs = require('../chunk-VJVRFKDH.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkDJFTZS4Pjs = require('../chunk-DJFTZS4P.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkCZ3AVCKDjs = require('../chunk-CZ3AVCKD.js');
|
|
13
|
+
require('../chunk-O6DPCPRH.js');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkO2SODTR3js = require('../chunk-O2SODTR3.js');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var _chunkCRTRMMJ7js = require('../chunk-CRTRMMJ7.js');
|
|
23
|
+
|
|
24
|
+
// src/nextjs/providers/NextAuthProvider.tsx
|
|
25
|
+
var _react = require('react');
|
|
26
|
+
var _reactquery = require('@tanstack/react-query');
|
|
27
|
+
|
|
28
|
+
// src/nextjs/hooks/useUserCookie.ts
|
|
29
|
+
|
|
30
|
+
var _navigationjs = require('next/navigation.js');
|
|
31
|
+
|
|
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 = _react.useRef.call(void 0, false);
|
|
67
|
+
const router = _navigationjs.useRouter.call(void 0, );
|
|
68
|
+
const { data: user } = _reactquery.useQuery.call(void 0, {
|
|
69
|
+
queryKey: ["user"],
|
|
70
|
+
queryFn: () => getUserFromCookie(),
|
|
71
|
+
refetchInterval: 2e3,
|
|
72
|
+
refetchIntervalInBackground: true,
|
|
73
|
+
enabled: !hasRunRef.current,
|
|
74
|
+
refetchOnWindowFocus: true
|
|
75
|
+
});
|
|
76
|
+
_react.useEffect.call(void 0, () => {
|
|
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
|
+
|
|
91
|
+
|
|
92
|
+
|
|
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 = _react.useRef.call(void 0, false);
|
|
102
|
+
const router = _navigationjs.useRouter.call(void 0, );
|
|
103
|
+
const { data: token } = _reactquery.useQuery.call(void 0, {
|
|
104
|
+
queryKey: ["token", tokenName],
|
|
105
|
+
queryFn: () => getTokenFromCookie(tokenName) || null,
|
|
106
|
+
refetchInterval: 2e3,
|
|
107
|
+
refetchIntervalInBackground: true,
|
|
108
|
+
enabled: !hasRunRef.current,
|
|
109
|
+
refetchOnWindowFocus: true
|
|
110
|
+
});
|
|
111
|
+
_react.useEffect.call(void 0, () => {
|
|
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
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
126
|
+
var queryClient = new (0, _reactquery.QueryClient)();
|
|
127
|
+
var CivicNextAuthProvider = (_a) => {
|
|
128
|
+
var _b = _a, {
|
|
129
|
+
children
|
|
130
|
+
} = _b, props = _chunkCRTRMMJ7js.__objRest.call(void 0, _b, [
|
|
131
|
+
"children"
|
|
132
|
+
]);
|
|
133
|
+
const [redirectUrl, setRedirectUrl] = _react.useState.call(void 0, "");
|
|
134
|
+
const resolvedConfig = _chunkCZ3AVCKDjs.resolveAuthConfig.call(void 0, );
|
|
135
|
+
const { clientId, oauthServer, callbackUrl, challengeUrl, logoutUrl } = resolvedConfig;
|
|
136
|
+
_react.useEffect.call(void 0, () => {
|
|
137
|
+
if (typeof globalThis.window !== "undefined") {
|
|
138
|
+
const currentUrl = globalThis.window.location.href;
|
|
139
|
+
setRedirectUrl(_chunkDJFTZS4Pjs.resolveCallbackUrl.call(void 0, resolvedConfig, currentUrl));
|
|
140
|
+
}
|
|
141
|
+
}, [callbackUrl, resolvedConfig]);
|
|
142
|
+
const user = useUserCookie();
|
|
143
|
+
const idToken = useTokenCookie("id_token" /* ID_TOKEN */);
|
|
144
|
+
const combinedUser = user ? _chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, user || {}), { idToken }) : null;
|
|
145
|
+
const sessionData = _chunkCRTRMMJ7js.__spreadValues.call(void 0, {
|
|
146
|
+
authenticated: !!user
|
|
147
|
+
}, idToken ? { idToken } : {});
|
|
148
|
+
const signOut = () => _chunkCRTRMMJ7js.__async.call(void 0, void 0, null, function* () {
|
|
149
|
+
if (props.onSignOut) {
|
|
150
|
+
yield props.onSignOut();
|
|
151
|
+
}
|
|
152
|
+
window.location.href = logoutUrl;
|
|
153
|
+
return;
|
|
154
|
+
});
|
|
155
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
156
|
+
_chunkVJVRFKDHjs.AuthProvider,
|
|
157
|
+
_chunkCRTRMMJ7js.__spreadProps.call(void 0, _chunkCRTRMMJ7js.__spreadValues.call(void 0, {}, props), {
|
|
158
|
+
redirectUrl,
|
|
159
|
+
config: { oauthServer },
|
|
160
|
+
clientId,
|
|
161
|
+
pkceConsumer: new (0, _chunkO2SODTR3js.ConfidentialClientPKCEConsumer)(challengeUrl),
|
|
162
|
+
sessionData,
|
|
163
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
164
|
+
_chunkVJVRFKDHjs.UserProvider,
|
|
165
|
+
{
|
|
166
|
+
storage: new (0, _chunkDJFTZS4Pjs.NextjsClientStorage)(),
|
|
167
|
+
user: combinedUser,
|
|
168
|
+
signOut,
|
|
169
|
+
children
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
})
|
|
173
|
+
) });
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
exports.CivicAuthProvider = CivicNextAuthProvider; exports.useUserCookie = useUserCookie;
|
|
179
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevincolgan/code/civic-auth/packages/civic-auth-client/dist/nextjs/client.js","../../src/nextjs/providers/NextAuthProvider.tsx","../../src/nextjs/hooks/useUserCookie.ts","../../src/lib/cookies.ts","../../src/nextjs/hooks/useTokenCookie.ts"],"names":["window","useRef","useRouter","useQuery","useEffect"],"mappings":"AAAA,yGAA6B;AAC7B;AACE;AACA;AACF,uDAA6B;AAC7B;AACE;AACA;AACF,uDAA6B;AAC7B;AACE;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,uDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,uDAA6B;AAC7B;AACA;ACnBA,8BAAoC;AAEpC,mDAAiD;ADoBjD;AACA;AE1BA;AACA,kDAA0B;AAC1B;AF4BA;AACA;AGhCA,IAAM,qBAAA,EAAuB,CAAC;AAAA,EAC5B,GAAA;AAAA,EACA,MAAA,EAAAA,OAAAA;AAAA,EACA,UAAA,EAAY;AACd,CAAA,EAAA,GAIM;AACJ,EAAA,MAAM,OAAA,EAASA,OAAAA,CAAO,QAAA,CAAS,MAAA;AAC/B,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ,OAAO,IAAA;AACpB,EAAA,MAAM,QAAA,EAAU,MAAA,CAAO,KAA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AAA;AAAA,UAEC;AAAA,QAAA;AAAA,MACH;AAAA,IAAA,CAAA;AAAA,EACF,EAAA,CACF,CAAA;AAEJ,CAAA;ADoGA;AACE;AACA;AACF,yFAAC","file":"/Users/kevincolgan/code/civic-auth/packages/civic-auth-client/dist/nextjs/client.js","sourcesContent":[null,"\"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"]}
|
|
@@ -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,i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AC;AAEhC,QAAM,OAAO,cAAc;AAC3B,QAAM,UAAU,wCAAmC;AACnD,QAAM,eAAe,OAAQ,iCAAM,QAAQ,CAAC,IAAf,EAAmB,QAAQ,KAAa;AACrE,QAAM,cAAc;AAAA,IAClB,eAAe,CAAC,CAAC;AAAA,KACb,UAAU,EAAE,QAAQ,IAAI,CAAC;AAE/B,QAAM,UAAU,MAA2B;AACzC,QAAI,MAAM,WAAW;AACnB,YAAM,MAAM,UAAU;AAAA,IACxB;AACA,WAAO,SAAS,OAAO;AACvB;AAAA,EACF;AACA,SACE,oBAAC,uBAAoB,QAAQ,aAC3B;AAAA,IAAC;AAAA,qCACK,QADL;AAAA,MAEC;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,11 +2,17 @@ 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 { T as TokensCookieConfig,
|
|
6
|
-
import { U as User } from './types-HdCjGldB.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';
|
|
7
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';
|
|
8
10
|
import 'oslo/oauth2';
|
|
9
11
|
|
|
12
|
+
type CookiesConfigObject = {
|
|
13
|
+
tokens: TokensCookieConfig;
|
|
14
|
+
user: CookieConfig;
|
|
15
|
+
};
|
|
10
16
|
type AuthConfigWithDefaults = {
|
|
11
17
|
clientId: string;
|
|
12
18
|
oauthServer: string;
|
|
@@ -17,10 +23,7 @@ type AuthConfigWithDefaults = {
|
|
|
17
23
|
challengeUrl: string;
|
|
18
24
|
include: string[];
|
|
19
25
|
exclude: string[];
|
|
20
|
-
cookies:
|
|
21
|
-
tokens: TokensCookieConfig;
|
|
22
|
-
user: CookieConfig;
|
|
23
|
-
};
|
|
26
|
+
cookies: CookiesConfigObject;
|
|
24
27
|
};
|
|
25
28
|
type AuthConfig = Partial<AuthConfigWithDefaults>;
|
|
26
29
|
/**
|
|
@@ -215,4 +218,29 @@ declare function auth(authConfig?: AuthConfig): (middleware: Middleware) => ((re
|
|
|
215
218
|
*/
|
|
216
219
|
declare const handler: (authConfig?: {}) => (request: NextRequest) => Promise<NextResponse>;
|
|
217
220
|
|
|
218
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Creates HTTP-only cookies for authentication tokens
|
|
223
|
+
*/
|
|
224
|
+
declare const createTokenCookies: (response: NextResponse$1, sessionData: SessionData, config: AuthConfig) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a client-readable cookie with user info
|
|
227
|
+
*/
|
|
228
|
+
declare const createUserInfoCookie: (response: NextResponse$1, user: User<UnknownObject> | null, sessionData: SessionData, config: AuthConfig) => void;
|
|
229
|
+
/**
|
|
230
|
+
* Clears all authentication cookies
|
|
231
|
+
*/
|
|
232
|
+
declare const clearAuthCookies: (config: AuthConfig) => Promise<void>;
|
|
233
|
+
type KeySetter = OAuthTokens | CodeVerifier;
|
|
234
|
+
declare class NextjsCookieStorage extends CookieStorage {
|
|
235
|
+
readonly config: Partial<TokensCookieConfig>;
|
|
236
|
+
constructor(config?: Partial<TokensCookieConfig>);
|
|
237
|
+
get(key: string): string | null;
|
|
238
|
+
set(key: KeySetter, value: string): void;
|
|
239
|
+
}
|
|
240
|
+
declare class NextjsClientStorage extends CookieStorage {
|
|
241
|
+
constructor(config?: Partial<CookieStorageSettings>);
|
|
242
|
+
get(key: string): string | null;
|
|
243
|
+
set(key: string, value: string): void;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { NextjsClientStorage, NextjsCookieStorage, auth, authMiddleware, clearAuthCookies, createCivicAuthPlugin, createTokenCookies, createUserInfoCookie, getUser, handler, withAuth };
|
package/dist/nextjs.d.ts
CHANGED
|
@@ -2,11 +2,17 @@ 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 { T as TokensCookieConfig,
|
|
6
|
-
import { U as User } from './types-HdCjGldB.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';
|
|
7
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';
|
|
8
10
|
import 'oslo/oauth2';
|
|
9
11
|
|
|
12
|
+
type CookiesConfigObject = {
|
|
13
|
+
tokens: TokensCookieConfig;
|
|
14
|
+
user: CookieConfig;
|
|
15
|
+
};
|
|
10
16
|
type AuthConfigWithDefaults = {
|
|
11
17
|
clientId: string;
|
|
12
18
|
oauthServer: string;
|
|
@@ -17,10 +23,7 @@ type AuthConfigWithDefaults = {
|
|
|
17
23
|
challengeUrl: string;
|
|
18
24
|
include: string[];
|
|
19
25
|
exclude: string[];
|
|
20
|
-
cookies:
|
|
21
|
-
tokens: TokensCookieConfig;
|
|
22
|
-
user: CookieConfig;
|
|
23
|
-
};
|
|
26
|
+
cookies: CookiesConfigObject;
|
|
24
27
|
};
|
|
25
28
|
type AuthConfig = Partial<AuthConfigWithDefaults>;
|
|
26
29
|
/**
|
|
@@ -215,4 +218,29 @@ declare function auth(authConfig?: AuthConfig): (middleware: Middleware) => ((re
|
|
|
215
218
|
*/
|
|
216
219
|
declare const handler: (authConfig?: {}) => (request: NextRequest) => Promise<NextResponse>;
|
|
217
220
|
|
|
218
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Creates HTTP-only cookies for authentication tokens
|
|
223
|
+
*/
|
|
224
|
+
declare const createTokenCookies: (response: NextResponse$1, sessionData: SessionData, config: AuthConfig) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a client-readable cookie with user info
|
|
227
|
+
*/
|
|
228
|
+
declare const createUserInfoCookie: (response: NextResponse$1, user: User<UnknownObject> | null, sessionData: SessionData, config: AuthConfig) => void;
|
|
229
|
+
/**
|
|
230
|
+
* Clears all authentication cookies
|
|
231
|
+
*/
|
|
232
|
+
declare const clearAuthCookies: (config: AuthConfig) => Promise<void>;
|
|
233
|
+
type KeySetter = OAuthTokens | CodeVerifier;
|
|
234
|
+
declare class NextjsCookieStorage extends CookieStorage {
|
|
235
|
+
readonly config: Partial<TokensCookieConfig>;
|
|
236
|
+
constructor(config?: Partial<TokensCookieConfig>);
|
|
237
|
+
get(key: string): string | null;
|
|
238
|
+
set(key: KeySetter, value: string): void;
|
|
239
|
+
}
|
|
240
|
+
declare class NextjsClientStorage extends CookieStorage {
|
|
241
|
+
constructor(config?: Partial<CookieStorageSettings>);
|
|
242
|
+
get(key: string): string | null;
|
|
243
|
+
set(key: string, value: string): void;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export { NextjsClientStorage, NextjsCookieStorage, auth, authMiddleware, clearAuthCookies, createCivicAuthPlugin, createTokenCookies, createUserInfoCookie, getUser, handler, withAuth };
|