@civic/auth 0.0.1-beta.0 → 0.0.1-beta.1
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 +10 -10
- package/dist/index-DFVNodC9.d.mts +66 -0
- package/dist/index-DFVNodC9.d.ts +66 -0
- package/dist/index.css +5 -5
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/nextjs.d.mts +235 -4
- package/dist/nextjs.d.ts +235 -4
- package/dist/nextjs.js +848 -42
- package/dist/nextjs.js.map +1 -1
- package/dist/nextjs.mjs +832 -43
- package/dist/nextjs.mjs.map +1 -1
- package/dist/react.d.mts +71 -19
- package/dist/react.d.ts +71 -19
- package/dist/react.js +599 -300
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +588 -293
- package/dist/react.mjs.map +1 -1
- package/package.json +22 -18
- package/dist/index-yT0eVchS.d.mts +0 -52
- package/dist/index-yT0eVchS.d.ts +0 -52
package/dist/nextjs.d.ts
CHANGED
|
@@ -1,8 +1,239 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as next_dist_shared_lib_image_config from 'next/dist/shared/lib/image-config';
|
|
2
|
+
import * as next_dist_lib_load_custom_routes from 'next/dist/lib/load-custom-routes';
|
|
3
|
+
import * as next_dist_server_config_shared from 'next/dist/server/config-shared';
|
|
4
|
+
import { NextConfig } from 'next';
|
|
5
|
+
import { NextRequest, NextResponse } from 'next/server.js';
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
interface CookieConfig {
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
sameSite?: "strict" | "lax" | "none";
|
|
10
|
+
domain?: string;
|
|
11
|
+
path?: string;
|
|
12
|
+
maxAge?: number;
|
|
13
|
+
}
|
|
14
|
+
type AuthConfigWithDefaults = {
|
|
15
|
+
clientId: string;
|
|
16
|
+
oauthServer: string;
|
|
17
|
+
callbackUrl: string;
|
|
4
18
|
loginUrl: string;
|
|
19
|
+
logoutUrl: string;
|
|
20
|
+
challengeUrl: string;
|
|
21
|
+
include: string[];
|
|
22
|
+
exclude: string[];
|
|
23
|
+
cookies: {
|
|
24
|
+
tokens: CookieConfig;
|
|
25
|
+
user: CookieConfig;
|
|
26
|
+
};
|
|
5
27
|
};
|
|
6
|
-
|
|
28
|
+
type AuthConfig = Partial<AuthConfigWithDefaults>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a Next.js plugin that handles auth configuration.
|
|
31
|
+
*
|
|
32
|
+
* This is the main configuration point for the auth system.
|
|
33
|
+
* Do not set _civic_auth_* environment variables directly - instead,
|
|
34
|
+
* pass your configuration here:
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```js
|
|
38
|
+
* // next.config.js
|
|
39
|
+
* export tefault createCivicAuthPlugin({
|
|
40
|
+
* clientId: 'my-client-id',
|
|
41
|
+
* callbackUrl: '/custom/callback',
|
|
42
|
+
* loginUrl: '/custom/login',
|
|
43
|
+
* logoutUrl: '/custom/logout',
|
|
44
|
+
* include: ['/protected/*'],
|
|
45
|
+
* exclude: ['/public/*']
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* The plugin sets internal environment variables that are used by
|
|
50
|
+
* the auth system. These variables should not be set manually.
|
|
51
|
+
*/
|
|
52
|
+
declare const createCivicAuthPlugin: (clientId: string, authConfig?: AuthConfig) => (nextConfig?: NextConfig) => {
|
|
53
|
+
env: {
|
|
54
|
+
_civic_auth_client_id: string;
|
|
55
|
+
_civic_oauth_server: string;
|
|
56
|
+
_civic_auth_callback_url: string;
|
|
57
|
+
_civic_auth_login_url: string;
|
|
58
|
+
_civic_auth_logout_url: string;
|
|
59
|
+
_civic_auth_includes: string;
|
|
60
|
+
_civic_auth_excludes: string;
|
|
61
|
+
_civic_auth_cookie_config: string;
|
|
62
|
+
};
|
|
63
|
+
exportPathMap?: (defaultMap: next_dist_server_config_shared.ExportPathMap, ctx: {
|
|
64
|
+
dev: boolean;
|
|
65
|
+
dir: string;
|
|
66
|
+
outDir: string | null;
|
|
67
|
+
distDir: string;
|
|
68
|
+
buildId: string;
|
|
69
|
+
}) => Promise<next_dist_server_config_shared.ExportPathMap> | next_dist_server_config_shared.ExportPathMap;
|
|
70
|
+
i18n?: next_dist_server_config_shared.I18NConfig | null;
|
|
71
|
+
eslint?: next_dist_server_config_shared.ESLintConfig;
|
|
72
|
+
typescript?: next_dist_server_config_shared.TypeScriptConfig;
|
|
73
|
+
headers?: () => Promise<next_dist_lib_load_custom_routes.Header[]>;
|
|
74
|
+
rewrites?: () => Promise<next_dist_lib_load_custom_routes.Rewrite[] | {
|
|
75
|
+
beforeFiles: next_dist_lib_load_custom_routes.Rewrite[];
|
|
76
|
+
afterFiles: next_dist_lib_load_custom_routes.Rewrite[];
|
|
77
|
+
fallback: next_dist_lib_load_custom_routes.Rewrite[];
|
|
78
|
+
}>;
|
|
79
|
+
redirects?: () => Promise<next_dist_lib_load_custom_routes.Redirect[]>;
|
|
80
|
+
excludeDefaultMomentLocales?: boolean;
|
|
81
|
+
webpack?: next_dist_server_config_shared.NextJsWebpackConfig | null;
|
|
82
|
+
trailingSlash?: boolean;
|
|
83
|
+
distDir?: string;
|
|
84
|
+
cleanDistDir?: boolean;
|
|
85
|
+
assetPrefix?: string;
|
|
86
|
+
cacheHandler?: string | undefined;
|
|
87
|
+
cacheMaxMemorySize?: number;
|
|
88
|
+
useFileSystemPublicRoutes?: boolean;
|
|
89
|
+
generateBuildId?: () => string | null | Promise<string | null>;
|
|
90
|
+
generateEtags?: boolean;
|
|
91
|
+
pageExtensions?: string[];
|
|
92
|
+
compress?: boolean;
|
|
93
|
+
analyticsId?: string;
|
|
94
|
+
poweredByHeader?: boolean;
|
|
95
|
+
images?: next_dist_shared_lib_image_config.ImageConfig;
|
|
96
|
+
devIndicators?: {
|
|
97
|
+
buildActivity?: boolean;
|
|
98
|
+
buildActivityPosition?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
99
|
+
};
|
|
100
|
+
onDemandEntries?: {
|
|
101
|
+
maxInactiveAge?: number;
|
|
102
|
+
pagesBufferLength?: number;
|
|
103
|
+
};
|
|
104
|
+
amp?: {
|
|
105
|
+
canonicalBase?: string;
|
|
106
|
+
};
|
|
107
|
+
deploymentId?: string;
|
|
108
|
+
basePath?: string;
|
|
109
|
+
sassOptions?: {
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
};
|
|
112
|
+
productionBrowserSourceMaps?: boolean;
|
|
113
|
+
optimizeFonts?: boolean;
|
|
114
|
+
reactProductionProfiling?: boolean;
|
|
115
|
+
reactStrictMode?: boolean | null;
|
|
116
|
+
publicRuntimeConfig?: {
|
|
117
|
+
[key: string]: any;
|
|
118
|
+
};
|
|
119
|
+
serverRuntimeConfig?: {
|
|
120
|
+
[key: string]: any;
|
|
121
|
+
};
|
|
122
|
+
httpAgentOptions?: {
|
|
123
|
+
keepAlive?: boolean;
|
|
124
|
+
};
|
|
125
|
+
outputFileTracing?: boolean;
|
|
126
|
+
staticPageGenerationTimeout?: number;
|
|
127
|
+
crossOrigin?: "anonymous" | "use-credentials";
|
|
128
|
+
swcMinify?: boolean;
|
|
129
|
+
compiler?: {
|
|
130
|
+
reactRemoveProperties?: boolean | {
|
|
131
|
+
properties?: string[];
|
|
132
|
+
};
|
|
133
|
+
relay?: {
|
|
134
|
+
src: string;
|
|
135
|
+
artifactDirectory?: string;
|
|
136
|
+
language?: "typescript" | "javascript" | "flow";
|
|
137
|
+
eagerEsModules?: boolean;
|
|
138
|
+
};
|
|
139
|
+
removeConsole?: boolean | {
|
|
140
|
+
exclude?: string[];
|
|
141
|
+
};
|
|
142
|
+
styledComponents?: boolean | next_dist_server_config_shared.StyledComponentsConfig;
|
|
143
|
+
emotion?: boolean | next_dist_server_config_shared.EmotionConfig;
|
|
144
|
+
styledJsx?: boolean | {
|
|
145
|
+
useLightningcss?: boolean;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
output?: "standalone" | "export";
|
|
149
|
+
transpilePackages?: string[];
|
|
150
|
+
skipMiddlewareUrlNormalize?: boolean;
|
|
151
|
+
skipTrailingSlashRedirect?: boolean;
|
|
152
|
+
modularizeImports?: Record<string, {
|
|
153
|
+
transform: string | Record<string, string>;
|
|
154
|
+
preventFullImport?: boolean;
|
|
155
|
+
skipDefaultConversion?: boolean;
|
|
156
|
+
}>;
|
|
157
|
+
logging?: {
|
|
158
|
+
fetches?: {
|
|
159
|
+
fullUrl?: boolean;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
experimental?: next_dist_server_config_shared.ExperimentalConfig;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Creates an authentication handler for Next.js API routes
|
|
167
|
+
*
|
|
168
|
+
* Usage:
|
|
169
|
+
* ```ts
|
|
170
|
+
* // app/api/auth/[...civicauth]/route.ts
|
|
171
|
+
* import { handler } from '@civic/auth/nextjs'
|
|
172
|
+
* export const GET = handler({
|
|
173
|
+
* // optional config overrides
|
|
174
|
+
* })
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function handler(authConfig?: AuthConfig): (request: NextRequest) => Promise<NextResponse>;
|
|
178
|
+
|
|
179
|
+
type UnknownObject = Record<string, unknown>;
|
|
180
|
+
type EmptyObject = Record<string, never>;
|
|
181
|
+
type ForwardedTokens = Record<string, {
|
|
182
|
+
idToken?: string;
|
|
183
|
+
accessToken?: string;
|
|
184
|
+
refreshToken?: string;
|
|
185
|
+
}>;
|
|
186
|
+
type Tokens = {
|
|
187
|
+
idToken: string;
|
|
188
|
+
accessToken: string;
|
|
189
|
+
refreshToken: string;
|
|
190
|
+
forwardedTokens: ForwardedTokens;
|
|
191
|
+
};
|
|
192
|
+
type BaseUser = {
|
|
193
|
+
id: string;
|
|
194
|
+
email?: string;
|
|
195
|
+
name?: string;
|
|
196
|
+
given_name?: string;
|
|
197
|
+
family_name?: string;
|
|
198
|
+
picture?: string;
|
|
199
|
+
updated_at?: Date;
|
|
200
|
+
};
|
|
201
|
+
type User<T extends UnknownObject = EmptyObject> = BaseUser & Tokens & T;
|
|
202
|
+
|
|
203
|
+
declare const getUser: () => User<UnknownObject> | null;
|
|
204
|
+
|
|
205
|
+
type Middleware = (request: NextRequest) => Promise<NextResponse> | NextResponse;
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
* Use this when auth is the only middleware you need.
|
|
209
|
+
* Usage:
|
|
210
|
+
*
|
|
211
|
+
* export default authMiddleware({ loginUrl = '/login' }); // or just authMiddleware();
|
|
212
|
+
*
|
|
213
|
+
*/
|
|
214
|
+
declare const authMiddleware: (authConfig?: Omit<AuthConfigWithDefaults, "clientId">) => (request: NextRequest) => Promise<NextResponse>;
|
|
215
|
+
/**
|
|
216
|
+
* Usage:
|
|
217
|
+
*
|
|
218
|
+
* export default withAuth(async (request) => {
|
|
219
|
+
* console.log('my middleware');
|
|
220
|
+
* return NextResponse.next();
|
|
221
|
+
* })
|
|
222
|
+
*/
|
|
223
|
+
declare function withAuth(middleware: Middleware): (request: NextRequest) => Promise<NextResponse>;
|
|
224
|
+
/**
|
|
225
|
+
* Use this when you want to configure the middleware here (an alternative is to do it in the next.config file)
|
|
226
|
+
*
|
|
227
|
+
* Usage:
|
|
228
|
+
*
|
|
229
|
+
* const withAuth = auth({ loginUrl = '/login' }); // or just auth();
|
|
230
|
+
*
|
|
231
|
+
* export default withAuth(async (request) => {
|
|
232
|
+
* console.log('my middleware');
|
|
233
|
+
* return NextResponse.next();
|
|
234
|
+
* })
|
|
235
|
+
*
|
|
236
|
+
*/
|
|
237
|
+
declare function auth(authConfig?: AuthConfig): (middleware: Middleware) => ((request: NextRequest) => Promise<NextResponse>);
|
|
7
238
|
|
|
8
|
-
export {
|
|
239
|
+
export { auth, authMiddleware, createCivicAuthPlugin, getUser, handler, withAuth };
|