@niledatabase/client 5.0.0-alpha.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/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/index.d.mts +244 -0
- package/dist/index.d.ts +244 -0
- package/dist/index.js +725 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +688 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 The Nile Platform
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="1434" alt="Screen Shot 2024-09-18 at 9 20 04 AM" src="https://github.com/user-attachments/assets/20585883-5cdc-4f15-93d3-dc150e87bc11">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Nile's Client SDK
|
|
8
|
+
|
|
9
|
+
This package (`@niledatabase/client`) is part of [Nile's Javascript SDK](https://github.com/niledatabase/nile-js/tree/main).
|
|
10
|
+
|
|
11
|
+
Nile's React package provides:
|
|
12
|
+
|
|
13
|
+
- 🎨 UI components for authentication, user management, and tenant management (customizable with Tailwind CSS)
|
|
14
|
+
- 🪝 React hooks for authentication, user management, and tenant management functionality
|
|
15
|
+
|
|
16
|
+
You can browse all the components and explore their properties in [Nile's documentation](https://www.thenile.dev/docs/auth/components/signin) or in [Storybook](https://storybook.thenile.dev).
|
|
17
|
+
|
|
18
|
+
The components and hooks are designed to work best and provide a secure user experience when used with the generated routes provided by [Nile's Server-Side SDK](https://www.npmjs.com/package/@niledatabase/server).
|
|
19
|
+
|
|
20
|
+
**Nile is a Postgres platform that decouples storage from compute, virtualizes tenants, and supports vertical and horizontal scaling globally to ship B2B applications fast while being safe with limitless scale.** All B2B applications are multi-tenant. A tenant/customer is primarily a company, an organization, or a workspace in your product that contains a group of users. A B2B application provides services to multiple tenants. Tenant is the basic building block of all B2B applications.
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @niledatabase/client
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Social Login (SSO)
|
|
31
|
+
|
|
32
|
+
Nile-Auth supports multiple social providers. You configure and enable them in [Nile console](https://console.thenile.dev), and then simply drop-in the components. For example, for Discord authentication:
|
|
33
|
+
|
|
34
|
+
## Learn more
|
|
35
|
+
|
|
36
|
+
- You can learn more about Nile and the SDK in [https://thenile.dev/docs]
|
|
37
|
+
- You can find detailed code examples in [our main repo](https://github.com/niledatabase/niledatabase)
|
|
38
|
+
- Nile SDK interacts with APIs in Nile Auth service. You can learn more about it in the [repository](https://github.com/niledatabase/nile-auth) and the [docs](https://thenile.dev/docs/auth)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { IncomingMessage } from 'http';
|
|
2
|
+
|
|
3
|
+
interface SignInResponse {
|
|
4
|
+
error: string | null;
|
|
5
|
+
status: number;
|
|
6
|
+
ok: boolean;
|
|
7
|
+
url: string | null;
|
|
8
|
+
}
|
|
9
|
+
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
|
10
|
+
interface SignInOptions extends Record<string, unknown> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
|
|
13
|
+
*
|
|
14
|
+
* [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
|
|
15
|
+
*/
|
|
16
|
+
callbackUrl?: string;
|
|
17
|
+
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
|
|
18
|
+
redirect?: boolean;
|
|
19
|
+
}
|
|
20
|
+
type SignInAuthorizationParams = string | string[][] | Record<string, string> | URLSearchParams;
|
|
21
|
+
type ProviderType = 'oauth' | 'email' | 'credentials';
|
|
22
|
+
interface ClientSafeProvider {
|
|
23
|
+
id: LiteralUnion<BuiltInProviderType>;
|
|
24
|
+
name: string;
|
|
25
|
+
type: ProviderType;
|
|
26
|
+
signinUrl: string;
|
|
27
|
+
callbackUrl: string;
|
|
28
|
+
}
|
|
29
|
+
type RedirectableProviderType = 'email' | 'credentials';
|
|
30
|
+
type OAuthProviderType = 'linkedin' | 'hubspot' | 'google' | 'azure-ad' | 'slack' | 'github' | 'twitter' | 'discord';
|
|
31
|
+
type BuiltInProviderType = RedirectableProviderType | OAuthProviderType;
|
|
32
|
+
type JWT = {
|
|
33
|
+
email: string;
|
|
34
|
+
sub: string;
|
|
35
|
+
id: string;
|
|
36
|
+
iat: number;
|
|
37
|
+
exp: number;
|
|
38
|
+
jti: string;
|
|
39
|
+
loading: boolean;
|
|
40
|
+
};
|
|
41
|
+
type ActiveSession = {
|
|
42
|
+
loading: boolean;
|
|
43
|
+
id: string;
|
|
44
|
+
email: string;
|
|
45
|
+
expires: string;
|
|
46
|
+
user?: {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
image: string;
|
|
50
|
+
email: string;
|
|
51
|
+
emailVerified: void | Date;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
type NonErrorSession = JWT | ActiveSession | null | undefined;
|
|
55
|
+
type NileSession = Response | NonErrorSession;
|
|
56
|
+
type AuthState = {
|
|
57
|
+
basePath: string;
|
|
58
|
+
baseUrl: string;
|
|
59
|
+
lastSync: number;
|
|
60
|
+
getSession: (...args: any[]) => void;
|
|
61
|
+
session: NonErrorSession | undefined | null;
|
|
62
|
+
loading: boolean;
|
|
63
|
+
};
|
|
64
|
+
type ListenerParams = {
|
|
65
|
+
key: ListenerKeys;
|
|
66
|
+
next: any;
|
|
67
|
+
prev: any;
|
|
68
|
+
};
|
|
69
|
+
type Listener = (callback: ListenerParams) => void;
|
|
70
|
+
type ListenerKeys = 'basePath' | 'baseUrl' | 'lastSync' | 'getSession' | 'session' | 'loading';
|
|
71
|
+
type AuthConfig = Config & {
|
|
72
|
+
listenerKeys?: Array<ListenerKeys>;
|
|
73
|
+
};
|
|
74
|
+
type Config = {
|
|
75
|
+
basePath?: string;
|
|
76
|
+
baseUrl?: string;
|
|
77
|
+
init?: RequestInit;
|
|
78
|
+
};
|
|
79
|
+
type PartialAuthorizer = null | {
|
|
80
|
+
state?: {
|
|
81
|
+
baseUrl?: string;
|
|
82
|
+
basePath?: string;
|
|
83
|
+
session?: {
|
|
84
|
+
user?: {
|
|
85
|
+
email?: string | undefined;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
requestInit?: RequestInit | undefined;
|
|
90
|
+
};
|
|
91
|
+
interface CtxOrReq {
|
|
92
|
+
req?: Partial<IncomingMessage> & {
|
|
93
|
+
body?: any;
|
|
94
|
+
};
|
|
95
|
+
ctx?: {
|
|
96
|
+
req: Partial<IncomingMessage> & {
|
|
97
|
+
body?: any;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
interface SignOutParams<R extends boolean = true> {
|
|
102
|
+
callbackUrl?: string;
|
|
103
|
+
redirect?: R;
|
|
104
|
+
}
|
|
105
|
+
interface SignOutResponse {
|
|
106
|
+
url: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type WarningCode = 'NEXTAUTH_URL' | 'NO_SECRET' | 'TWITTER_OAUTH_2_BETA' | 'DEBUG_ENABLED';
|
|
110
|
+
/**
|
|
111
|
+
* Override any of the methods, and the rest will use the default logger.
|
|
112
|
+
*
|
|
113
|
+
* [Documentation](https://next-auth.js.org/configuration/options#logger)
|
|
114
|
+
*/
|
|
115
|
+
interface LoggerInstance extends Record<string, (...args: any) => any> {
|
|
116
|
+
warn: (code: WarningCode) => void;
|
|
117
|
+
error: (code: string,
|
|
118
|
+
/**
|
|
119
|
+
* Either an instance of (JSON serializable) Error
|
|
120
|
+
* or an object that contains some debug information.
|
|
121
|
+
* (Error is still available through `metadata.error`)
|
|
122
|
+
*/
|
|
123
|
+
metadata: Error | {
|
|
124
|
+
error: Error;
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
}) => void;
|
|
127
|
+
debug: (code: string, metadata: unknown) => void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type GetSessionParams = CtxOrReq & {
|
|
131
|
+
event?: 'storage' | 'timer' | 'hidden' | string;
|
|
132
|
+
triggerEvent?: boolean;
|
|
133
|
+
broadcast?: boolean;
|
|
134
|
+
baseUrl?: string;
|
|
135
|
+
init?: RequestInit;
|
|
136
|
+
};
|
|
137
|
+
declare enum State {
|
|
138
|
+
SESSION = "getSession"
|
|
139
|
+
}
|
|
140
|
+
declare class Authorizer {
|
|
141
|
+
state: AuthState;
|
|
142
|
+
logger: LoggerInstance;
|
|
143
|
+
requestInit?: RequestInit;
|
|
144
|
+
addListener: (cb: Listener) => void;
|
|
145
|
+
removeListener: (cb: Listener) => void;
|
|
146
|
+
status: null | State;
|
|
147
|
+
constructor(config?: AuthConfig);
|
|
148
|
+
sync(event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange'): Promise<void>;
|
|
149
|
+
set baseUrl(val: string);
|
|
150
|
+
get baseUrl(): string;
|
|
151
|
+
configure(config?: Config): this;
|
|
152
|
+
sanitize(): PartialAuthorizer;
|
|
153
|
+
initialize(params?: {
|
|
154
|
+
baseUrl?: string;
|
|
155
|
+
session?: NonErrorSession | null | undefined;
|
|
156
|
+
event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange';
|
|
157
|
+
}): Promise<void>;
|
|
158
|
+
get apiBaseUrl(): string;
|
|
159
|
+
sendData(url: string, init?: RequestInit): Promise<Response | undefined>;
|
|
160
|
+
fetchData<T = any>(url: string, init?: RequestInit): Promise<T | undefined>;
|
|
161
|
+
fetchFormData<T = {
|
|
162
|
+
url: string;
|
|
163
|
+
}>(url: string, init: RequestInit): Promise<{
|
|
164
|
+
data: T;
|
|
165
|
+
status: number;
|
|
166
|
+
ok: boolean;
|
|
167
|
+
url: string;
|
|
168
|
+
} | undefined>;
|
|
169
|
+
getProviders(url?: string): Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
|
|
170
|
+
getCsrfToken(url?: string): Promise<string | undefined>;
|
|
171
|
+
getSession(params?: GetSessionParams): Promise<NonErrorSession>;
|
|
172
|
+
refreshSession(): Promise<NonErrorSession>;
|
|
173
|
+
signOut<R extends boolean = true>(options?: SignOutParams<R> & {
|
|
174
|
+
baseUrl?: string;
|
|
175
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
176
|
+
fetchUrl?: string;
|
|
177
|
+
basePath?: string;
|
|
178
|
+
}): Promise<R extends true ? undefined : SignOutResponse>;
|
|
179
|
+
signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions & {
|
|
180
|
+
baseUrl?: string;
|
|
181
|
+
providersUrl?: string;
|
|
182
|
+
csrfUrl?: string;
|
|
183
|
+
init?: ResponseInit;
|
|
184
|
+
fetchUrl?: string;
|
|
185
|
+
resetUrl?: string;
|
|
186
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
187
|
+
}, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
|
|
188
|
+
signUp(options: {
|
|
189
|
+
baseUrl?: string;
|
|
190
|
+
init?: ResponseInit;
|
|
191
|
+
fetchUrl?: string;
|
|
192
|
+
newTenantName?: string;
|
|
193
|
+
createTenant?: string | boolean;
|
|
194
|
+
email: string;
|
|
195
|
+
password: string;
|
|
196
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
197
|
+
tenantId?: string;
|
|
198
|
+
callbackUrl?: string;
|
|
199
|
+
redirect?: boolean;
|
|
200
|
+
}): Promise<any>;
|
|
201
|
+
resetPassword(options: {
|
|
202
|
+
baseUrl?: string;
|
|
203
|
+
init?: ResponseInit;
|
|
204
|
+
fetchUrl?: string;
|
|
205
|
+
email: string;
|
|
206
|
+
password: string;
|
|
207
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
208
|
+
callbackUrl?: string;
|
|
209
|
+
redirect?: boolean;
|
|
210
|
+
}): Promise<Response | undefined>;
|
|
211
|
+
_configureFetch(params: {
|
|
212
|
+
baseUrl?: string;
|
|
213
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
214
|
+
init?: RequestInit;
|
|
215
|
+
}): void;
|
|
216
|
+
}
|
|
217
|
+
declare const authorizer: Authorizer;
|
|
218
|
+
declare const auth: Authorizer;
|
|
219
|
+
declare const getSession: (params?: GetSessionParams) => Promise<NonErrorSession>;
|
|
220
|
+
declare const getCsrfToken: (url?: string) => Promise<string | undefined>;
|
|
221
|
+
declare const getProviders: () => Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
|
|
222
|
+
declare const signOut: typeof authorizer.signOut;
|
|
223
|
+
declare const signIn: typeof authorizer.signIn;
|
|
224
|
+
declare const signUp: typeof authorizer.signUp;
|
|
225
|
+
declare const resetPassword: typeof authorizer.resetPassword;
|
|
226
|
+
|
|
227
|
+
declare function getStatus(load: boolean, sess: NonErrorSession | null | undefined): "loading" | "authenticated" | "unauthenticated";
|
|
228
|
+
|
|
229
|
+
interface BroadcastMessage {
|
|
230
|
+
event?: 'session';
|
|
231
|
+
data?: {
|
|
232
|
+
trigger?: 'signout' | 'getSession';
|
|
233
|
+
};
|
|
234
|
+
clientId: string;
|
|
235
|
+
timestamp: number;
|
|
236
|
+
}
|
|
237
|
+
declare const broadcast: {
|
|
238
|
+
/** Get notified by other tabs/windows. */
|
|
239
|
+
receive(onReceive: (message: BroadcastMessage) => void): () => void;
|
|
240
|
+
/** Notify other tabs/windows. */
|
|
241
|
+
post(message: Record<string, unknown>): void;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { type ActiveSession, type AuthConfig, type AuthState, Authorizer, type BuiltInProviderType, type ClientSafeProvider, type Config, type CtxOrReq, type JWT, type Listener, type ListenerKeys, type ListenerParams, type LiteralUnion, type NileSession, type NonErrorSession, type PartialAuthorizer, type ProviderType, type RedirectableProviderType, type SignInAuthorizationParams, type SignInOptions, type SignInResponse, type SignOutParams, type SignOutResponse, auth, broadcast, getCsrfToken, getProviders, getSession, getStatus, resetPassword, signIn, signOut, signUp };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { IncomingMessage } from 'http';
|
|
2
|
+
|
|
3
|
+
interface SignInResponse {
|
|
4
|
+
error: string | null;
|
|
5
|
+
status: number;
|
|
6
|
+
ok: boolean;
|
|
7
|
+
url: string | null;
|
|
8
|
+
}
|
|
9
|
+
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
|
10
|
+
interface SignInOptions extends Record<string, unknown> {
|
|
11
|
+
/**
|
|
12
|
+
* Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
|
|
13
|
+
*
|
|
14
|
+
* [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
|
|
15
|
+
*/
|
|
16
|
+
callbackUrl?: string;
|
|
17
|
+
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
|
|
18
|
+
redirect?: boolean;
|
|
19
|
+
}
|
|
20
|
+
type SignInAuthorizationParams = string | string[][] | Record<string, string> | URLSearchParams;
|
|
21
|
+
type ProviderType = 'oauth' | 'email' | 'credentials';
|
|
22
|
+
interface ClientSafeProvider {
|
|
23
|
+
id: LiteralUnion<BuiltInProviderType>;
|
|
24
|
+
name: string;
|
|
25
|
+
type: ProviderType;
|
|
26
|
+
signinUrl: string;
|
|
27
|
+
callbackUrl: string;
|
|
28
|
+
}
|
|
29
|
+
type RedirectableProviderType = 'email' | 'credentials';
|
|
30
|
+
type OAuthProviderType = 'linkedin' | 'hubspot' | 'google' | 'azure-ad' | 'slack' | 'github' | 'twitter' | 'discord';
|
|
31
|
+
type BuiltInProviderType = RedirectableProviderType | OAuthProviderType;
|
|
32
|
+
type JWT = {
|
|
33
|
+
email: string;
|
|
34
|
+
sub: string;
|
|
35
|
+
id: string;
|
|
36
|
+
iat: number;
|
|
37
|
+
exp: number;
|
|
38
|
+
jti: string;
|
|
39
|
+
loading: boolean;
|
|
40
|
+
};
|
|
41
|
+
type ActiveSession = {
|
|
42
|
+
loading: boolean;
|
|
43
|
+
id: string;
|
|
44
|
+
email: string;
|
|
45
|
+
expires: string;
|
|
46
|
+
user?: {
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
image: string;
|
|
50
|
+
email: string;
|
|
51
|
+
emailVerified: void | Date;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
type NonErrorSession = JWT | ActiveSession | null | undefined;
|
|
55
|
+
type NileSession = Response | NonErrorSession;
|
|
56
|
+
type AuthState = {
|
|
57
|
+
basePath: string;
|
|
58
|
+
baseUrl: string;
|
|
59
|
+
lastSync: number;
|
|
60
|
+
getSession: (...args: any[]) => void;
|
|
61
|
+
session: NonErrorSession | undefined | null;
|
|
62
|
+
loading: boolean;
|
|
63
|
+
};
|
|
64
|
+
type ListenerParams = {
|
|
65
|
+
key: ListenerKeys;
|
|
66
|
+
next: any;
|
|
67
|
+
prev: any;
|
|
68
|
+
};
|
|
69
|
+
type Listener = (callback: ListenerParams) => void;
|
|
70
|
+
type ListenerKeys = 'basePath' | 'baseUrl' | 'lastSync' | 'getSession' | 'session' | 'loading';
|
|
71
|
+
type AuthConfig = Config & {
|
|
72
|
+
listenerKeys?: Array<ListenerKeys>;
|
|
73
|
+
};
|
|
74
|
+
type Config = {
|
|
75
|
+
basePath?: string;
|
|
76
|
+
baseUrl?: string;
|
|
77
|
+
init?: RequestInit;
|
|
78
|
+
};
|
|
79
|
+
type PartialAuthorizer = null | {
|
|
80
|
+
state?: {
|
|
81
|
+
baseUrl?: string;
|
|
82
|
+
basePath?: string;
|
|
83
|
+
session?: {
|
|
84
|
+
user?: {
|
|
85
|
+
email?: string | undefined;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
requestInit?: RequestInit | undefined;
|
|
90
|
+
};
|
|
91
|
+
interface CtxOrReq {
|
|
92
|
+
req?: Partial<IncomingMessage> & {
|
|
93
|
+
body?: any;
|
|
94
|
+
};
|
|
95
|
+
ctx?: {
|
|
96
|
+
req: Partial<IncomingMessage> & {
|
|
97
|
+
body?: any;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
interface SignOutParams<R extends boolean = true> {
|
|
102
|
+
callbackUrl?: string;
|
|
103
|
+
redirect?: R;
|
|
104
|
+
}
|
|
105
|
+
interface SignOutResponse {
|
|
106
|
+
url: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type WarningCode = 'NEXTAUTH_URL' | 'NO_SECRET' | 'TWITTER_OAUTH_2_BETA' | 'DEBUG_ENABLED';
|
|
110
|
+
/**
|
|
111
|
+
* Override any of the methods, and the rest will use the default logger.
|
|
112
|
+
*
|
|
113
|
+
* [Documentation](https://next-auth.js.org/configuration/options#logger)
|
|
114
|
+
*/
|
|
115
|
+
interface LoggerInstance extends Record<string, (...args: any) => any> {
|
|
116
|
+
warn: (code: WarningCode) => void;
|
|
117
|
+
error: (code: string,
|
|
118
|
+
/**
|
|
119
|
+
* Either an instance of (JSON serializable) Error
|
|
120
|
+
* or an object that contains some debug information.
|
|
121
|
+
* (Error is still available through `metadata.error`)
|
|
122
|
+
*/
|
|
123
|
+
metadata: Error | {
|
|
124
|
+
error: Error;
|
|
125
|
+
[key: string]: unknown;
|
|
126
|
+
}) => void;
|
|
127
|
+
debug: (code: string, metadata: unknown) => void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type GetSessionParams = CtxOrReq & {
|
|
131
|
+
event?: 'storage' | 'timer' | 'hidden' | string;
|
|
132
|
+
triggerEvent?: boolean;
|
|
133
|
+
broadcast?: boolean;
|
|
134
|
+
baseUrl?: string;
|
|
135
|
+
init?: RequestInit;
|
|
136
|
+
};
|
|
137
|
+
declare enum State {
|
|
138
|
+
SESSION = "getSession"
|
|
139
|
+
}
|
|
140
|
+
declare class Authorizer {
|
|
141
|
+
state: AuthState;
|
|
142
|
+
logger: LoggerInstance;
|
|
143
|
+
requestInit?: RequestInit;
|
|
144
|
+
addListener: (cb: Listener) => void;
|
|
145
|
+
removeListener: (cb: Listener) => void;
|
|
146
|
+
status: null | State;
|
|
147
|
+
constructor(config?: AuthConfig);
|
|
148
|
+
sync(event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange'): Promise<void>;
|
|
149
|
+
set baseUrl(val: string);
|
|
150
|
+
get baseUrl(): string;
|
|
151
|
+
configure(config?: Config): this;
|
|
152
|
+
sanitize(): PartialAuthorizer;
|
|
153
|
+
initialize(params?: {
|
|
154
|
+
baseUrl?: string;
|
|
155
|
+
session?: NonErrorSession | null | undefined;
|
|
156
|
+
event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange';
|
|
157
|
+
}): Promise<void>;
|
|
158
|
+
get apiBaseUrl(): string;
|
|
159
|
+
sendData(url: string, init?: RequestInit): Promise<Response | undefined>;
|
|
160
|
+
fetchData<T = any>(url: string, init?: RequestInit): Promise<T | undefined>;
|
|
161
|
+
fetchFormData<T = {
|
|
162
|
+
url: string;
|
|
163
|
+
}>(url: string, init: RequestInit): Promise<{
|
|
164
|
+
data: T;
|
|
165
|
+
status: number;
|
|
166
|
+
ok: boolean;
|
|
167
|
+
url: string;
|
|
168
|
+
} | undefined>;
|
|
169
|
+
getProviders(url?: string): Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
|
|
170
|
+
getCsrfToken(url?: string): Promise<string | undefined>;
|
|
171
|
+
getSession(params?: GetSessionParams): Promise<NonErrorSession>;
|
|
172
|
+
refreshSession(): Promise<NonErrorSession>;
|
|
173
|
+
signOut<R extends boolean = true>(options?: SignOutParams<R> & {
|
|
174
|
+
baseUrl?: string;
|
|
175
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
176
|
+
fetchUrl?: string;
|
|
177
|
+
basePath?: string;
|
|
178
|
+
}): Promise<R extends true ? undefined : SignOutResponse>;
|
|
179
|
+
signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions & {
|
|
180
|
+
baseUrl?: string;
|
|
181
|
+
providersUrl?: string;
|
|
182
|
+
csrfUrl?: string;
|
|
183
|
+
init?: ResponseInit;
|
|
184
|
+
fetchUrl?: string;
|
|
185
|
+
resetUrl?: string;
|
|
186
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
187
|
+
}, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
|
|
188
|
+
signUp(options: {
|
|
189
|
+
baseUrl?: string;
|
|
190
|
+
init?: ResponseInit;
|
|
191
|
+
fetchUrl?: string;
|
|
192
|
+
newTenantName?: string;
|
|
193
|
+
createTenant?: string | boolean;
|
|
194
|
+
email: string;
|
|
195
|
+
password: string;
|
|
196
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
197
|
+
tenantId?: string;
|
|
198
|
+
callbackUrl?: string;
|
|
199
|
+
redirect?: boolean;
|
|
200
|
+
}): Promise<any>;
|
|
201
|
+
resetPassword(options: {
|
|
202
|
+
baseUrl?: string;
|
|
203
|
+
init?: ResponseInit;
|
|
204
|
+
fetchUrl?: string;
|
|
205
|
+
email: string;
|
|
206
|
+
password: string;
|
|
207
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
208
|
+
callbackUrl?: string;
|
|
209
|
+
redirect?: boolean;
|
|
210
|
+
}): Promise<Response | undefined>;
|
|
211
|
+
_configureFetch(params: {
|
|
212
|
+
baseUrl?: string;
|
|
213
|
+
auth?: Authorizer | PartialAuthorizer;
|
|
214
|
+
init?: RequestInit;
|
|
215
|
+
}): void;
|
|
216
|
+
}
|
|
217
|
+
declare const authorizer: Authorizer;
|
|
218
|
+
declare const auth: Authorizer;
|
|
219
|
+
declare const getSession: (params?: GetSessionParams) => Promise<NonErrorSession>;
|
|
220
|
+
declare const getCsrfToken: (url?: string) => Promise<string | undefined>;
|
|
221
|
+
declare const getProviders: () => Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
|
|
222
|
+
declare const signOut: typeof authorizer.signOut;
|
|
223
|
+
declare const signIn: typeof authorizer.signIn;
|
|
224
|
+
declare const signUp: typeof authorizer.signUp;
|
|
225
|
+
declare const resetPassword: typeof authorizer.resetPassword;
|
|
226
|
+
|
|
227
|
+
declare function getStatus(load: boolean, sess: NonErrorSession | null | undefined): "loading" | "authenticated" | "unauthenticated";
|
|
228
|
+
|
|
229
|
+
interface BroadcastMessage {
|
|
230
|
+
event?: 'session';
|
|
231
|
+
data?: {
|
|
232
|
+
trigger?: 'signout' | 'getSession';
|
|
233
|
+
};
|
|
234
|
+
clientId: string;
|
|
235
|
+
timestamp: number;
|
|
236
|
+
}
|
|
237
|
+
declare const broadcast: {
|
|
238
|
+
/** Get notified by other tabs/windows. */
|
|
239
|
+
receive(onReceive: (message: BroadcastMessage) => void): () => void;
|
|
240
|
+
/** Notify other tabs/windows. */
|
|
241
|
+
post(message: Record<string, unknown>): void;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export { type ActiveSession, type AuthConfig, type AuthState, Authorizer, type BuiltInProviderType, type ClientSafeProvider, type Config, type CtxOrReq, type JWT, type Listener, type ListenerKeys, type ListenerParams, type LiteralUnion, type NileSession, type NonErrorSession, type PartialAuthorizer, type ProviderType, type RedirectableProviderType, type SignInAuthorizationParams, type SignInOptions, type SignInResponse, type SignOutParams, type SignOutResponse, auth, broadcast, getCsrfToken, getProviders, getSession, getStatus, resetPassword, signIn, signOut, signUp };
|