@hono/auth-js 1.0.0

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.
@@ -0,0 +1,153 @@
1
+ import { BuiltInProviderType, ProviderType, RedirectableProviderType } from '@auth/core/providers';
2
+ import { Session } from '@auth/core/types';
3
+ import * as React from 'react';
4
+
5
+ interface AuthClientConfig {
6
+ baseUrl: string;
7
+ basePath: string;
8
+ credentials?: RequestCredentials;
9
+ /** Stores last session response */
10
+ _session?: Session | null | undefined;
11
+ /** Used for timestamp since last sycned (in seconds) */
12
+ _lastSync: number;
13
+ /**
14
+ * Stores the `SessionProvider`'s session update method to be able to
15
+ * trigger session updates from places like `signIn` or `signOut`
16
+ */
17
+ _getSession: (...args: any[]) => any;
18
+ }
19
+ interface UseSessionOptions<R extends boolean> {
20
+ required: R;
21
+ /** Defaults to `signIn` */
22
+ onUnauthenticated?: () => void;
23
+ }
24
+ type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
25
+ interface ClientSafeProvider {
26
+ id: LiteralUnion<BuiltInProviderType>;
27
+ name: string;
28
+ type: ProviderType;
29
+ signinUrl: string;
30
+ callbackUrl: string;
31
+ }
32
+ interface SignInOptions extends Record<string, unknown> {
33
+ /**
34
+ * Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
35
+ *
36
+ * [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
37
+ */
38
+ callbackUrl?: string;
39
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
40
+ redirect?: boolean;
41
+ }
42
+ interface SignInResponse {
43
+ error: string | undefined;
44
+ status: number;
45
+ ok: boolean;
46
+ url: string | null;
47
+ }
48
+ /**
49
+ * Match `inputType` of `new URLSearchParams(inputType)`
50
+ * @internal
51
+ */
52
+ type SignInAuthorizationParams = string | string[][] | Record<string, string> | URLSearchParams;
53
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1) */
54
+ interface SignOutResponse {
55
+ url: string;
56
+ }
57
+ interface SignOutParams<R extends boolean = true> {
58
+ /** [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl-1) */
59
+ callbackUrl?: string;
60
+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
61
+ redirect?: R;
62
+ }
63
+ /**
64
+
65
+ * If you have session expiry times of 30 days (the default) or more, then you probably don't need to change any of the default options.
66
+ *
67
+ * However, if you need to customize the session behavior and/or are using short session expiry times, you can pass options to the provider to customize the behavior of the {@link useSession} hook.
68
+ */
69
+ interface SessionProviderProps {
70
+ children: React.ReactNode;
71
+ session?: Session | null;
72
+ baseUrl?: string;
73
+ basePath?: string;
74
+ /**
75
+ * A time interval (in seconds) after which the session will be re-fetched.
76
+ * If set to `0` (default), the session is not polled.
77
+ */
78
+ refetchInterval?: number;
79
+ /**
80
+ * `SessionProvider` automatically refetches the session when the user switches between windows.
81
+ * This option activates this behaviour if set to `true` (default).
82
+ */
83
+ refetchOnWindowFocus?: boolean;
84
+ /**
85
+ * Set to `false` to stop polling when the device has no internet access offline (determined by `navigator.onLine`)
86
+ *
87
+ * [`navigator.onLine` documentation](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)
88
+ */
89
+ refetchWhenOffline?: false;
90
+ }
91
+
92
+ declare class AuthConfigManager {
93
+ private static instance;
94
+ _config: AuthClientConfig;
95
+ static getInstance(): AuthConfigManager;
96
+ setConfig(userConfig: Partial<AuthClientConfig>): void;
97
+ getConfig(): AuthClientConfig;
98
+ }
99
+ declare const authConfigManager: AuthConfigManager;
100
+ /** @todo Document */
101
+ type UpdateSession = (data?: any) => Promise<Session | null>;
102
+ type SessionContextValue<R extends boolean = false> = R extends true ? {
103
+ update: UpdateSession;
104
+ data: Session;
105
+ status: 'authenticated';
106
+ } | {
107
+ update: UpdateSession;
108
+ data: null;
109
+ status: 'loading';
110
+ } : {
111
+ update: UpdateSession;
112
+ data: Session;
113
+ status: 'authenticated';
114
+ } | {
115
+ update: UpdateSession;
116
+ data: null;
117
+ status: 'unauthenticated' | 'loading';
118
+ };
119
+ declare const SessionContext: React.Context<{
120
+ update: UpdateSession;
121
+ data: Session;
122
+ status: 'authenticated';
123
+ } | {
124
+ update: UpdateSession;
125
+ data: null;
126
+ status: 'unauthenticated' | 'loading';
127
+ } | undefined>;
128
+ declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
129
+ interface GetSessionParams {
130
+ event?: 'storage' | 'timer' | 'hidden' | string;
131
+ triggerEvent?: boolean;
132
+ broadcast?: boolean;
133
+ }
134
+ declare function getSession(params?: GetSessionParams): Promise<Session | null>;
135
+ /**
136
+ * Returns the current Cross-Site Request Forgery Token (CSRF Token)
137
+ * required to make requests that changes state. (e.g. signing in or out, or updating the session).
138
+ *
139
+ * [CSRF Prevention: Double Submit Cookie](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookie)
140
+ * @internal
141
+ */
142
+ declare function getCsrfToken(): Promise<string>;
143
+ type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
144
+ declare function getProviders(): Promise<ProvidersType | null>;
145
+ declare function signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
146
+ /**
147
+ * Initiate a signout, by destroying the current session.
148
+ * Handles CSRF protection.
149
+ */
150
+ declare function signOut<R extends boolean = true>(options?: SignOutParams<R>): Promise<R extends true ? undefined : SignOutResponse>;
151
+ declare function SessionProvider(props: SessionProviderProps): React.JSX.Element;
152
+
153
+ export { type GetSessionParams, type LiteralUnion, SessionContext, type SessionContextValue, SessionProvider, type SessionProviderProps, type SignInAuthorizationParams, type SignInOptions, type SignInResponse, type SignOutParams, type UpdateSession, authConfigManager, getCsrfToken, getProviders, getSession, signIn, signOut, useSession };