@authon/react-native 0.3.8 → 0.3.9
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/index.cjs +12 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +314 -0
- package/dist/index.d.ts +314 -0
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { AuthonUser as AuthonUser$1, OAuthProviderType, BrandingConfig, Web3Chain, Web3WalletType, Web3NonceResponse, Web3Wallet, PasskeyCredential } from '@authon/shared';
|
|
4
|
+
export { BrandingConfig, OAuthProviderType } from '@authon/shared';
|
|
5
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
6
|
+
|
|
7
|
+
type AuthonUser = AuthonUser$1;
|
|
8
|
+
interface AuthonReactNativeConfig {
|
|
9
|
+
publishableKey: string;
|
|
10
|
+
apiUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
interface AuthState {
|
|
13
|
+
isLoaded: boolean;
|
|
14
|
+
isSignedIn: boolean;
|
|
15
|
+
userId: string | null;
|
|
16
|
+
sessionId: string | null;
|
|
17
|
+
accessToken: string | null;
|
|
18
|
+
}
|
|
19
|
+
interface SignInParams {
|
|
20
|
+
strategy: 'email_password' | 'oauth';
|
|
21
|
+
email?: string;
|
|
22
|
+
password?: string;
|
|
23
|
+
provider?: string;
|
|
24
|
+
}
|
|
25
|
+
interface SignUpParams {
|
|
26
|
+
email: string;
|
|
27
|
+
password: string;
|
|
28
|
+
displayName?: string;
|
|
29
|
+
}
|
|
30
|
+
type OAuthFlowMode = 'popup' | 'redirect' | 'auto';
|
|
31
|
+
interface StartOAuthOptions {
|
|
32
|
+
redirectUri?: string;
|
|
33
|
+
returnTo?: string;
|
|
34
|
+
flow?: OAuthFlowMode;
|
|
35
|
+
}
|
|
36
|
+
type AuthonEventType = 'signedIn' | 'signedOut' | 'error' | 'tokenRefreshed';
|
|
37
|
+
interface AuthonEvents {
|
|
38
|
+
signedIn: (user: AuthonUser) => void;
|
|
39
|
+
signedOut: () => void;
|
|
40
|
+
error: (error: Error) => void;
|
|
41
|
+
tokenRefreshed: () => void;
|
|
42
|
+
}
|
|
43
|
+
interface TokenPair {
|
|
44
|
+
accessToken: string;
|
|
45
|
+
refreshToken: string;
|
|
46
|
+
expiresAt: number;
|
|
47
|
+
}
|
|
48
|
+
interface ApiAuthResponse {
|
|
49
|
+
accessToken: string;
|
|
50
|
+
refreshToken: string;
|
|
51
|
+
expiresIn: number;
|
|
52
|
+
user: AuthonUser;
|
|
53
|
+
}
|
|
54
|
+
interface OAuthCompletedResponse extends ApiAuthResponse {
|
|
55
|
+
status: 'completed';
|
|
56
|
+
}
|
|
57
|
+
interface OAuthErrorResponse {
|
|
58
|
+
status: 'error';
|
|
59
|
+
message: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type TokenStorage = {
|
|
63
|
+
getItem(key: string): Promise<string | null>;
|
|
64
|
+
setItem(key: string, value: string): Promise<void>;
|
|
65
|
+
removeItem(key: string): Promise<void>;
|
|
66
|
+
};
|
|
67
|
+
type OAuthPollResponse = OAuthCompletedResponse | OAuthErrorResponse;
|
|
68
|
+
declare class AuthonMobileClient {
|
|
69
|
+
private apiUrl;
|
|
70
|
+
private publishableKey;
|
|
71
|
+
private storageKey;
|
|
72
|
+
private tokens;
|
|
73
|
+
private user;
|
|
74
|
+
private storage;
|
|
75
|
+
private refreshInFlight;
|
|
76
|
+
private refreshTimer;
|
|
77
|
+
private listeners;
|
|
78
|
+
private _providers;
|
|
79
|
+
private _branding;
|
|
80
|
+
private _initialized;
|
|
81
|
+
constructor(config: AuthonReactNativeConfig);
|
|
82
|
+
setStorage(storage: TokenStorage): void;
|
|
83
|
+
initialize(): Promise<TokenPair | null>;
|
|
84
|
+
/** Fetch providers + branding from API (lazy, cached) */
|
|
85
|
+
ensureInitialized(): Promise<void>;
|
|
86
|
+
signIn(params: SignInParams): Promise<{
|
|
87
|
+
tokens: TokenPair;
|
|
88
|
+
user: AuthonUser;
|
|
89
|
+
} | {
|
|
90
|
+
needsVerification: true;
|
|
91
|
+
email: string;
|
|
92
|
+
} | {
|
|
93
|
+
mfaRequired: true;
|
|
94
|
+
mfaToken: string;
|
|
95
|
+
}>;
|
|
96
|
+
signUp(params: SignUpParams): Promise<{
|
|
97
|
+
tokens: TokenPair;
|
|
98
|
+
user: AuthonUser;
|
|
99
|
+
} | {
|
|
100
|
+
needsVerification: true;
|
|
101
|
+
email: string;
|
|
102
|
+
}>;
|
|
103
|
+
verifyEmail(email: string, code: string): Promise<{
|
|
104
|
+
tokens: TokenPair;
|
|
105
|
+
user: AuthonUser;
|
|
106
|
+
}>;
|
|
107
|
+
resendVerificationCode(email: string): Promise<void>;
|
|
108
|
+
signOut(): Promise<void>;
|
|
109
|
+
getUser(): Promise<AuthonUser | null>;
|
|
110
|
+
getCachedUser(): AuthonUser | null;
|
|
111
|
+
refreshToken(refreshToken?: string): Promise<TokenPair | null>;
|
|
112
|
+
private _doRefresh;
|
|
113
|
+
getAccessToken(): string | null;
|
|
114
|
+
isAuthenticated(): boolean;
|
|
115
|
+
getProviders(): Promise<OAuthProviderType[]>;
|
|
116
|
+
getBranding(): Promise<BrandingConfig | null>;
|
|
117
|
+
getOAuthUrl(provider: string, options?: string | StartOAuthOptions): Promise<{
|
|
118
|
+
url: string;
|
|
119
|
+
state: string;
|
|
120
|
+
}>;
|
|
121
|
+
pollOAuth(state: string): Promise<OAuthPollResponse | null>;
|
|
122
|
+
/** Poll for OAuth completion (3 minute timeout, matching JS SDK) */
|
|
123
|
+
completeOAuth(state: string): Promise<{
|
|
124
|
+
tokens: TokenPair;
|
|
125
|
+
user: AuthonUser;
|
|
126
|
+
}>;
|
|
127
|
+
getApiUrl(): string;
|
|
128
|
+
web3GetNonce(address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number): Promise<Web3NonceResponse>;
|
|
129
|
+
web3Verify(message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType): Promise<{
|
|
130
|
+
tokens: TokenPair;
|
|
131
|
+
user: AuthonUser;
|
|
132
|
+
}>;
|
|
133
|
+
web3GetWallets(): Promise<Web3Wallet[]>;
|
|
134
|
+
web3LinkWallet(params: {
|
|
135
|
+
address: string;
|
|
136
|
+
chain: Web3Chain;
|
|
137
|
+
walletType: Web3WalletType;
|
|
138
|
+
chainId?: number;
|
|
139
|
+
message: string;
|
|
140
|
+
signature: string;
|
|
141
|
+
}): Promise<Web3Wallet>;
|
|
142
|
+
web3UnlinkWallet(walletId: string): Promise<void>;
|
|
143
|
+
passwordlessSendCode(identifier: string, type?: 'email' | 'sms'): Promise<void>;
|
|
144
|
+
passwordlessVerifyCode(identifier: string, code: string): Promise<{
|
|
145
|
+
tokens: TokenPair;
|
|
146
|
+
user: AuthonUser;
|
|
147
|
+
}>;
|
|
148
|
+
passkeyStartRegister(name?: string): Promise<{
|
|
149
|
+
options: Record<string, unknown>;
|
|
150
|
+
}>;
|
|
151
|
+
passkeyCompleteRegister(credential: Record<string, unknown>): Promise<PasskeyCredential>;
|
|
152
|
+
passkeyStartAuth(email?: string): Promise<{
|
|
153
|
+
options: Record<string, unknown>;
|
|
154
|
+
}>;
|
|
155
|
+
passkeyCompleteAuth(credential: Record<string, unknown>): Promise<{
|
|
156
|
+
tokens: TokenPair;
|
|
157
|
+
user: AuthonUser;
|
|
158
|
+
}>;
|
|
159
|
+
passkeyList(): Promise<PasskeyCredential[]>;
|
|
160
|
+
passkeyDelete(credentialId: string): Promise<void>;
|
|
161
|
+
on<K extends AuthonEventType>(event: K, listener: AuthonEvents[K]): () => void;
|
|
162
|
+
private emit;
|
|
163
|
+
destroy(): void;
|
|
164
|
+
private clearSession;
|
|
165
|
+
private clearRefreshTimer;
|
|
166
|
+
/** Schedule auto-refresh 60 seconds before token expiry (like JS SDK) */
|
|
167
|
+
private scheduleRefresh;
|
|
168
|
+
private persistTokens;
|
|
169
|
+
private toTokenPair;
|
|
170
|
+
private requestAuth;
|
|
171
|
+
private request;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interface AuthonContextValue extends AuthState {
|
|
175
|
+
user: AuthonUser | null;
|
|
176
|
+
signIn: (params: SignInParams) => Promise<any>;
|
|
177
|
+
signUp: (params: SignUpParams) => Promise<any>;
|
|
178
|
+
signOut: () => Promise<void>;
|
|
179
|
+
getToken: () => string | null;
|
|
180
|
+
/** Available OAuth providers (fetched from API) */
|
|
181
|
+
providers: OAuthProviderType[];
|
|
182
|
+
/** Branding config (fetched from API) */
|
|
183
|
+
branding: BrandingConfig | null;
|
|
184
|
+
/** Start OAuth flow — returns { url, state }. Open url in browser, then call completeOAuth(state) */
|
|
185
|
+
startOAuth: (provider: OAuthProviderType, options?: string | StartOAuthOptions) => Promise<{
|
|
186
|
+
url: string;
|
|
187
|
+
state: string;
|
|
188
|
+
}>;
|
|
189
|
+
/** Poll for OAuth result after user completes browser flow */
|
|
190
|
+
completeOAuth: (state: string) => Promise<void>;
|
|
191
|
+
/** Subscribe to auth events */
|
|
192
|
+
on: <K extends AuthonEventType>(event: K, listener: AuthonEvents[K]) => () => void;
|
|
193
|
+
/** Get the underlying client instance */
|
|
194
|
+
client: AuthonMobileClient;
|
|
195
|
+
}
|
|
196
|
+
declare const AuthonContext: React.Context<AuthonContextValue | null>;
|
|
197
|
+
interface AuthonProviderProps extends AuthonReactNativeConfig {
|
|
198
|
+
children: React.ReactNode;
|
|
199
|
+
storage?: {
|
|
200
|
+
getItem(key: string): Promise<string | null>;
|
|
201
|
+
setItem(key: string, value: string): Promise<void>;
|
|
202
|
+
removeItem(key: string): Promise<void>;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
declare function AuthonProvider({ children, storage, ...config }: AuthonProviderProps): react_jsx_runtime.JSX.Element;
|
|
206
|
+
|
|
207
|
+
declare function useAuthon(): AuthonContextValue;
|
|
208
|
+
|
|
209
|
+
declare function useUser(): {
|
|
210
|
+
isLoaded: boolean;
|
|
211
|
+
isSignedIn: boolean;
|
|
212
|
+
user: AuthonUser | null;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
interface Web3LinkWalletParams {
|
|
216
|
+
address: string;
|
|
217
|
+
chain: Web3Chain;
|
|
218
|
+
walletType: Web3WalletType;
|
|
219
|
+
chainId?: number;
|
|
220
|
+
message: string;
|
|
221
|
+
signature: string;
|
|
222
|
+
}
|
|
223
|
+
interface UseAuthonWeb3Return {
|
|
224
|
+
getNonce: (address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number) => Promise<Web3NonceResponse | null>;
|
|
225
|
+
verify: (message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType) => Promise<boolean>;
|
|
226
|
+
getWallets: () => Promise<Web3Wallet[] | null>;
|
|
227
|
+
linkWallet: (params: Web3LinkWalletParams) => Promise<Web3Wallet | null>;
|
|
228
|
+
unlinkWallet: (walletId: string) => Promise<boolean>;
|
|
229
|
+
isLoading: boolean;
|
|
230
|
+
error: Error | null;
|
|
231
|
+
}
|
|
232
|
+
declare function useAuthonWeb3(): UseAuthonWeb3Return;
|
|
233
|
+
|
|
234
|
+
interface UseAuthonPasswordlessReturn {
|
|
235
|
+
sendCode: (identifier: string, type?: 'email' | 'sms') => Promise<boolean>;
|
|
236
|
+
verifyCode: (identifier: string, code: string) => Promise<{
|
|
237
|
+
tokens: TokenPair;
|
|
238
|
+
user: AuthonUser;
|
|
239
|
+
} | null>;
|
|
240
|
+
isLoading: boolean;
|
|
241
|
+
error: Error | null;
|
|
242
|
+
}
|
|
243
|
+
declare function useAuthonPasswordless(): UseAuthonPasswordlessReturn;
|
|
244
|
+
|
|
245
|
+
interface UseAuthonPasskeysReturn {
|
|
246
|
+
startRegister: (name?: string) => Promise<{
|
|
247
|
+
options: Record<string, unknown>;
|
|
248
|
+
} | null>;
|
|
249
|
+
completeRegister: (credential: Record<string, unknown>) => Promise<PasskeyCredential | null>;
|
|
250
|
+
startAuth: (email?: string) => Promise<{
|
|
251
|
+
options: Record<string, unknown>;
|
|
252
|
+
} | null>;
|
|
253
|
+
completeAuth: (credential: Record<string, unknown>) => Promise<{
|
|
254
|
+
tokens: TokenPair;
|
|
255
|
+
user: AuthonUser;
|
|
256
|
+
} | null>;
|
|
257
|
+
listPasskeys: () => Promise<PasskeyCredential[] | null>;
|
|
258
|
+
deletePasskey: (credentialId: string) => Promise<boolean>;
|
|
259
|
+
isLoading: boolean;
|
|
260
|
+
error: Error | null;
|
|
261
|
+
}
|
|
262
|
+
declare function useAuthonPasskeys(): UseAuthonPasskeysReturn;
|
|
263
|
+
|
|
264
|
+
interface IconProps {
|
|
265
|
+
size?: number;
|
|
266
|
+
color?: string;
|
|
267
|
+
}
|
|
268
|
+
declare function ProviderIcon({ provider, size, color }: IconProps & {
|
|
269
|
+
provider: OAuthProviderType;
|
|
270
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
271
|
+
|
|
272
|
+
interface SocialButtonProps {
|
|
273
|
+
provider: OAuthProviderType;
|
|
274
|
+
onPress: (provider: OAuthProviderType) => void;
|
|
275
|
+
loading?: boolean;
|
|
276
|
+
disabled?: boolean;
|
|
277
|
+
/** Override button label. Default: "Continue with {Provider}" */
|
|
278
|
+
label?: string;
|
|
279
|
+
/** Compact mode — icon-only square button (default: false) */
|
|
280
|
+
compact?: boolean;
|
|
281
|
+
/** Override button style */
|
|
282
|
+
style?: ViewStyle;
|
|
283
|
+
/** Override label text style */
|
|
284
|
+
labelStyle?: TextStyle;
|
|
285
|
+
/** Icon size (default: 20, compact default: 24) */
|
|
286
|
+
iconSize?: number;
|
|
287
|
+
/** Border radius (default: 10) */
|
|
288
|
+
borderRadius?: number;
|
|
289
|
+
/** Button height (default: 48) */
|
|
290
|
+
height?: number;
|
|
291
|
+
/** Button size for compact mode (default: 48) */
|
|
292
|
+
size?: number;
|
|
293
|
+
}
|
|
294
|
+
declare function SocialButton({ provider, onPress, loading, disabled, label, compact, style, labelStyle, iconSize, borderRadius, height, size, }: SocialButtonProps): react_jsx_runtime.JSX.Element;
|
|
295
|
+
|
|
296
|
+
interface SocialButtonsProps {
|
|
297
|
+
/** Called after successful OAuth sign-in */
|
|
298
|
+
onSuccess?: () => void;
|
|
299
|
+
/** Called on OAuth error */
|
|
300
|
+
onError?: (error: Error) => void;
|
|
301
|
+
/** Container style */
|
|
302
|
+
style?: ViewStyle;
|
|
303
|
+
/** Gap between buttons (default: 10, compact default: 12) */
|
|
304
|
+
gap?: number;
|
|
305
|
+
/** Compact mode — icon-only square buttons in a row (default: false) */
|
|
306
|
+
compact?: boolean;
|
|
307
|
+
/** Custom labels per provider. e.g. { google: 'Google로 로그인' } */
|
|
308
|
+
labels?: Partial<Record<OAuthProviderType, string>>;
|
|
309
|
+
/** Props to pass through to each SocialButton */
|
|
310
|
+
buttonProps?: Partial<Omit<SocialButtonProps, 'provider' | 'onPress' | 'loading' | 'disabled' | 'compact' | 'label'>>;
|
|
311
|
+
}
|
|
312
|
+
declare function SocialButtons({ onSuccess, onError, style, gap, compact, labels, buttonProps, }: SocialButtonsProps): react_jsx_runtime.JSX.Element | null;
|
|
313
|
+
|
|
314
|
+
export { type AuthState, AuthonContext, type AuthonContextValue, type AuthonEventType, type AuthonEvents, AuthonMobileClient, AuthonProvider, type AuthonReactNativeConfig, type AuthonUser, type OAuthCompletedResponse, type OAuthErrorResponse, type OAuthFlowMode, ProviderIcon, type SignInParams, type SignUpParams, SocialButton, type SocialButtonProps, SocialButtons, type SocialButtonsProps, type StartOAuthOptions, type TokenPair, type UseAuthonPasskeysReturn, type UseAuthonPasswordlessReturn, type UseAuthonWeb3Return, type Web3LinkWalletParams, useAuthon, useAuthonPasskeys, useAuthonPasswordless, useAuthonWeb3, useUser };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { AuthonUser as AuthonUser$1, OAuthProviderType, BrandingConfig, Web3Chain, Web3WalletType, Web3NonceResponse, Web3Wallet, PasskeyCredential } from '@authon/shared';
|
|
4
|
+
export { BrandingConfig, OAuthProviderType } from '@authon/shared';
|
|
5
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
6
|
+
|
|
7
|
+
type AuthonUser = AuthonUser$1;
|
|
8
|
+
interface AuthonReactNativeConfig {
|
|
9
|
+
publishableKey: string;
|
|
10
|
+
apiUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
interface AuthState {
|
|
13
|
+
isLoaded: boolean;
|
|
14
|
+
isSignedIn: boolean;
|
|
15
|
+
userId: string | null;
|
|
16
|
+
sessionId: string | null;
|
|
17
|
+
accessToken: string | null;
|
|
18
|
+
}
|
|
19
|
+
interface SignInParams {
|
|
20
|
+
strategy: 'email_password' | 'oauth';
|
|
21
|
+
email?: string;
|
|
22
|
+
password?: string;
|
|
23
|
+
provider?: string;
|
|
24
|
+
}
|
|
25
|
+
interface SignUpParams {
|
|
26
|
+
email: string;
|
|
27
|
+
password: string;
|
|
28
|
+
displayName?: string;
|
|
29
|
+
}
|
|
30
|
+
type OAuthFlowMode = 'popup' | 'redirect' | 'auto';
|
|
31
|
+
interface StartOAuthOptions {
|
|
32
|
+
redirectUri?: string;
|
|
33
|
+
returnTo?: string;
|
|
34
|
+
flow?: OAuthFlowMode;
|
|
35
|
+
}
|
|
36
|
+
type AuthonEventType = 'signedIn' | 'signedOut' | 'error' | 'tokenRefreshed';
|
|
37
|
+
interface AuthonEvents {
|
|
38
|
+
signedIn: (user: AuthonUser) => void;
|
|
39
|
+
signedOut: () => void;
|
|
40
|
+
error: (error: Error) => void;
|
|
41
|
+
tokenRefreshed: () => void;
|
|
42
|
+
}
|
|
43
|
+
interface TokenPair {
|
|
44
|
+
accessToken: string;
|
|
45
|
+
refreshToken: string;
|
|
46
|
+
expiresAt: number;
|
|
47
|
+
}
|
|
48
|
+
interface ApiAuthResponse {
|
|
49
|
+
accessToken: string;
|
|
50
|
+
refreshToken: string;
|
|
51
|
+
expiresIn: number;
|
|
52
|
+
user: AuthonUser;
|
|
53
|
+
}
|
|
54
|
+
interface OAuthCompletedResponse extends ApiAuthResponse {
|
|
55
|
+
status: 'completed';
|
|
56
|
+
}
|
|
57
|
+
interface OAuthErrorResponse {
|
|
58
|
+
status: 'error';
|
|
59
|
+
message: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type TokenStorage = {
|
|
63
|
+
getItem(key: string): Promise<string | null>;
|
|
64
|
+
setItem(key: string, value: string): Promise<void>;
|
|
65
|
+
removeItem(key: string): Promise<void>;
|
|
66
|
+
};
|
|
67
|
+
type OAuthPollResponse = OAuthCompletedResponse | OAuthErrorResponse;
|
|
68
|
+
declare class AuthonMobileClient {
|
|
69
|
+
private apiUrl;
|
|
70
|
+
private publishableKey;
|
|
71
|
+
private storageKey;
|
|
72
|
+
private tokens;
|
|
73
|
+
private user;
|
|
74
|
+
private storage;
|
|
75
|
+
private refreshInFlight;
|
|
76
|
+
private refreshTimer;
|
|
77
|
+
private listeners;
|
|
78
|
+
private _providers;
|
|
79
|
+
private _branding;
|
|
80
|
+
private _initialized;
|
|
81
|
+
constructor(config: AuthonReactNativeConfig);
|
|
82
|
+
setStorage(storage: TokenStorage): void;
|
|
83
|
+
initialize(): Promise<TokenPair | null>;
|
|
84
|
+
/** Fetch providers + branding from API (lazy, cached) */
|
|
85
|
+
ensureInitialized(): Promise<void>;
|
|
86
|
+
signIn(params: SignInParams): Promise<{
|
|
87
|
+
tokens: TokenPair;
|
|
88
|
+
user: AuthonUser;
|
|
89
|
+
} | {
|
|
90
|
+
needsVerification: true;
|
|
91
|
+
email: string;
|
|
92
|
+
} | {
|
|
93
|
+
mfaRequired: true;
|
|
94
|
+
mfaToken: string;
|
|
95
|
+
}>;
|
|
96
|
+
signUp(params: SignUpParams): Promise<{
|
|
97
|
+
tokens: TokenPair;
|
|
98
|
+
user: AuthonUser;
|
|
99
|
+
} | {
|
|
100
|
+
needsVerification: true;
|
|
101
|
+
email: string;
|
|
102
|
+
}>;
|
|
103
|
+
verifyEmail(email: string, code: string): Promise<{
|
|
104
|
+
tokens: TokenPair;
|
|
105
|
+
user: AuthonUser;
|
|
106
|
+
}>;
|
|
107
|
+
resendVerificationCode(email: string): Promise<void>;
|
|
108
|
+
signOut(): Promise<void>;
|
|
109
|
+
getUser(): Promise<AuthonUser | null>;
|
|
110
|
+
getCachedUser(): AuthonUser | null;
|
|
111
|
+
refreshToken(refreshToken?: string): Promise<TokenPair | null>;
|
|
112
|
+
private _doRefresh;
|
|
113
|
+
getAccessToken(): string | null;
|
|
114
|
+
isAuthenticated(): boolean;
|
|
115
|
+
getProviders(): Promise<OAuthProviderType[]>;
|
|
116
|
+
getBranding(): Promise<BrandingConfig | null>;
|
|
117
|
+
getOAuthUrl(provider: string, options?: string | StartOAuthOptions): Promise<{
|
|
118
|
+
url: string;
|
|
119
|
+
state: string;
|
|
120
|
+
}>;
|
|
121
|
+
pollOAuth(state: string): Promise<OAuthPollResponse | null>;
|
|
122
|
+
/** Poll for OAuth completion (3 minute timeout, matching JS SDK) */
|
|
123
|
+
completeOAuth(state: string): Promise<{
|
|
124
|
+
tokens: TokenPair;
|
|
125
|
+
user: AuthonUser;
|
|
126
|
+
}>;
|
|
127
|
+
getApiUrl(): string;
|
|
128
|
+
web3GetNonce(address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number): Promise<Web3NonceResponse>;
|
|
129
|
+
web3Verify(message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType): Promise<{
|
|
130
|
+
tokens: TokenPair;
|
|
131
|
+
user: AuthonUser;
|
|
132
|
+
}>;
|
|
133
|
+
web3GetWallets(): Promise<Web3Wallet[]>;
|
|
134
|
+
web3LinkWallet(params: {
|
|
135
|
+
address: string;
|
|
136
|
+
chain: Web3Chain;
|
|
137
|
+
walletType: Web3WalletType;
|
|
138
|
+
chainId?: number;
|
|
139
|
+
message: string;
|
|
140
|
+
signature: string;
|
|
141
|
+
}): Promise<Web3Wallet>;
|
|
142
|
+
web3UnlinkWallet(walletId: string): Promise<void>;
|
|
143
|
+
passwordlessSendCode(identifier: string, type?: 'email' | 'sms'): Promise<void>;
|
|
144
|
+
passwordlessVerifyCode(identifier: string, code: string): Promise<{
|
|
145
|
+
tokens: TokenPair;
|
|
146
|
+
user: AuthonUser;
|
|
147
|
+
}>;
|
|
148
|
+
passkeyStartRegister(name?: string): Promise<{
|
|
149
|
+
options: Record<string, unknown>;
|
|
150
|
+
}>;
|
|
151
|
+
passkeyCompleteRegister(credential: Record<string, unknown>): Promise<PasskeyCredential>;
|
|
152
|
+
passkeyStartAuth(email?: string): Promise<{
|
|
153
|
+
options: Record<string, unknown>;
|
|
154
|
+
}>;
|
|
155
|
+
passkeyCompleteAuth(credential: Record<string, unknown>): Promise<{
|
|
156
|
+
tokens: TokenPair;
|
|
157
|
+
user: AuthonUser;
|
|
158
|
+
}>;
|
|
159
|
+
passkeyList(): Promise<PasskeyCredential[]>;
|
|
160
|
+
passkeyDelete(credentialId: string): Promise<void>;
|
|
161
|
+
on<K extends AuthonEventType>(event: K, listener: AuthonEvents[K]): () => void;
|
|
162
|
+
private emit;
|
|
163
|
+
destroy(): void;
|
|
164
|
+
private clearSession;
|
|
165
|
+
private clearRefreshTimer;
|
|
166
|
+
/** Schedule auto-refresh 60 seconds before token expiry (like JS SDK) */
|
|
167
|
+
private scheduleRefresh;
|
|
168
|
+
private persistTokens;
|
|
169
|
+
private toTokenPair;
|
|
170
|
+
private requestAuth;
|
|
171
|
+
private request;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
interface AuthonContextValue extends AuthState {
|
|
175
|
+
user: AuthonUser | null;
|
|
176
|
+
signIn: (params: SignInParams) => Promise<any>;
|
|
177
|
+
signUp: (params: SignUpParams) => Promise<any>;
|
|
178
|
+
signOut: () => Promise<void>;
|
|
179
|
+
getToken: () => string | null;
|
|
180
|
+
/** Available OAuth providers (fetched from API) */
|
|
181
|
+
providers: OAuthProviderType[];
|
|
182
|
+
/** Branding config (fetched from API) */
|
|
183
|
+
branding: BrandingConfig | null;
|
|
184
|
+
/** Start OAuth flow — returns { url, state }. Open url in browser, then call completeOAuth(state) */
|
|
185
|
+
startOAuth: (provider: OAuthProviderType, options?: string | StartOAuthOptions) => Promise<{
|
|
186
|
+
url: string;
|
|
187
|
+
state: string;
|
|
188
|
+
}>;
|
|
189
|
+
/** Poll for OAuth result after user completes browser flow */
|
|
190
|
+
completeOAuth: (state: string) => Promise<void>;
|
|
191
|
+
/** Subscribe to auth events */
|
|
192
|
+
on: <K extends AuthonEventType>(event: K, listener: AuthonEvents[K]) => () => void;
|
|
193
|
+
/** Get the underlying client instance */
|
|
194
|
+
client: AuthonMobileClient;
|
|
195
|
+
}
|
|
196
|
+
declare const AuthonContext: React.Context<AuthonContextValue | null>;
|
|
197
|
+
interface AuthonProviderProps extends AuthonReactNativeConfig {
|
|
198
|
+
children: React.ReactNode;
|
|
199
|
+
storage?: {
|
|
200
|
+
getItem(key: string): Promise<string | null>;
|
|
201
|
+
setItem(key: string, value: string): Promise<void>;
|
|
202
|
+
removeItem(key: string): Promise<void>;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
declare function AuthonProvider({ children, storage, ...config }: AuthonProviderProps): react_jsx_runtime.JSX.Element;
|
|
206
|
+
|
|
207
|
+
declare function useAuthon(): AuthonContextValue;
|
|
208
|
+
|
|
209
|
+
declare function useUser(): {
|
|
210
|
+
isLoaded: boolean;
|
|
211
|
+
isSignedIn: boolean;
|
|
212
|
+
user: AuthonUser | null;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
interface Web3LinkWalletParams {
|
|
216
|
+
address: string;
|
|
217
|
+
chain: Web3Chain;
|
|
218
|
+
walletType: Web3WalletType;
|
|
219
|
+
chainId?: number;
|
|
220
|
+
message: string;
|
|
221
|
+
signature: string;
|
|
222
|
+
}
|
|
223
|
+
interface UseAuthonWeb3Return {
|
|
224
|
+
getNonce: (address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number) => Promise<Web3NonceResponse | null>;
|
|
225
|
+
verify: (message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType) => Promise<boolean>;
|
|
226
|
+
getWallets: () => Promise<Web3Wallet[] | null>;
|
|
227
|
+
linkWallet: (params: Web3LinkWalletParams) => Promise<Web3Wallet | null>;
|
|
228
|
+
unlinkWallet: (walletId: string) => Promise<boolean>;
|
|
229
|
+
isLoading: boolean;
|
|
230
|
+
error: Error | null;
|
|
231
|
+
}
|
|
232
|
+
declare function useAuthonWeb3(): UseAuthonWeb3Return;
|
|
233
|
+
|
|
234
|
+
interface UseAuthonPasswordlessReturn {
|
|
235
|
+
sendCode: (identifier: string, type?: 'email' | 'sms') => Promise<boolean>;
|
|
236
|
+
verifyCode: (identifier: string, code: string) => Promise<{
|
|
237
|
+
tokens: TokenPair;
|
|
238
|
+
user: AuthonUser;
|
|
239
|
+
} | null>;
|
|
240
|
+
isLoading: boolean;
|
|
241
|
+
error: Error | null;
|
|
242
|
+
}
|
|
243
|
+
declare function useAuthonPasswordless(): UseAuthonPasswordlessReturn;
|
|
244
|
+
|
|
245
|
+
interface UseAuthonPasskeysReturn {
|
|
246
|
+
startRegister: (name?: string) => Promise<{
|
|
247
|
+
options: Record<string, unknown>;
|
|
248
|
+
} | null>;
|
|
249
|
+
completeRegister: (credential: Record<string, unknown>) => Promise<PasskeyCredential | null>;
|
|
250
|
+
startAuth: (email?: string) => Promise<{
|
|
251
|
+
options: Record<string, unknown>;
|
|
252
|
+
} | null>;
|
|
253
|
+
completeAuth: (credential: Record<string, unknown>) => Promise<{
|
|
254
|
+
tokens: TokenPair;
|
|
255
|
+
user: AuthonUser;
|
|
256
|
+
} | null>;
|
|
257
|
+
listPasskeys: () => Promise<PasskeyCredential[] | null>;
|
|
258
|
+
deletePasskey: (credentialId: string) => Promise<boolean>;
|
|
259
|
+
isLoading: boolean;
|
|
260
|
+
error: Error | null;
|
|
261
|
+
}
|
|
262
|
+
declare function useAuthonPasskeys(): UseAuthonPasskeysReturn;
|
|
263
|
+
|
|
264
|
+
interface IconProps {
|
|
265
|
+
size?: number;
|
|
266
|
+
color?: string;
|
|
267
|
+
}
|
|
268
|
+
declare function ProviderIcon({ provider, size, color }: IconProps & {
|
|
269
|
+
provider: OAuthProviderType;
|
|
270
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
271
|
+
|
|
272
|
+
interface SocialButtonProps {
|
|
273
|
+
provider: OAuthProviderType;
|
|
274
|
+
onPress: (provider: OAuthProviderType) => void;
|
|
275
|
+
loading?: boolean;
|
|
276
|
+
disabled?: boolean;
|
|
277
|
+
/** Override button label. Default: "Continue with {Provider}" */
|
|
278
|
+
label?: string;
|
|
279
|
+
/** Compact mode — icon-only square button (default: false) */
|
|
280
|
+
compact?: boolean;
|
|
281
|
+
/** Override button style */
|
|
282
|
+
style?: ViewStyle;
|
|
283
|
+
/** Override label text style */
|
|
284
|
+
labelStyle?: TextStyle;
|
|
285
|
+
/** Icon size (default: 20, compact default: 24) */
|
|
286
|
+
iconSize?: number;
|
|
287
|
+
/** Border radius (default: 10) */
|
|
288
|
+
borderRadius?: number;
|
|
289
|
+
/** Button height (default: 48) */
|
|
290
|
+
height?: number;
|
|
291
|
+
/** Button size for compact mode (default: 48) */
|
|
292
|
+
size?: number;
|
|
293
|
+
}
|
|
294
|
+
declare function SocialButton({ provider, onPress, loading, disabled, label, compact, style, labelStyle, iconSize, borderRadius, height, size, }: SocialButtonProps): react_jsx_runtime.JSX.Element;
|
|
295
|
+
|
|
296
|
+
interface SocialButtonsProps {
|
|
297
|
+
/** Called after successful OAuth sign-in */
|
|
298
|
+
onSuccess?: () => void;
|
|
299
|
+
/** Called on OAuth error */
|
|
300
|
+
onError?: (error: Error) => void;
|
|
301
|
+
/** Container style */
|
|
302
|
+
style?: ViewStyle;
|
|
303
|
+
/** Gap between buttons (default: 10, compact default: 12) */
|
|
304
|
+
gap?: number;
|
|
305
|
+
/** Compact mode — icon-only square buttons in a row (default: false) */
|
|
306
|
+
compact?: boolean;
|
|
307
|
+
/** Custom labels per provider. e.g. { google: 'Google로 로그인' } */
|
|
308
|
+
labels?: Partial<Record<OAuthProviderType, string>>;
|
|
309
|
+
/** Props to pass through to each SocialButton */
|
|
310
|
+
buttonProps?: Partial<Omit<SocialButtonProps, 'provider' | 'onPress' | 'loading' | 'disabled' | 'compact' | 'label'>>;
|
|
311
|
+
}
|
|
312
|
+
declare function SocialButtons({ onSuccess, onError, style, gap, compact, labels, buttonProps, }: SocialButtonsProps): react_jsx_runtime.JSX.Element | null;
|
|
313
|
+
|
|
314
|
+
export { type AuthState, AuthonContext, type AuthonContextValue, type AuthonEventType, type AuthonEvents, AuthonMobileClient, AuthonProvider, type AuthonReactNativeConfig, type AuthonUser, type OAuthCompletedResponse, type OAuthErrorResponse, type OAuthFlowMode, ProviderIcon, type SignInParams, type SignUpParams, SocialButton, type SocialButtonProps, SocialButtons, type SocialButtonsProps, type StartOAuthOptions, type TokenPair, type UseAuthonPasskeysReturn, type UseAuthonPasswordlessReturn, type UseAuthonWeb3Return, type Web3LinkWalletParams, useAuthon, useAuthonPasskeys, useAuthonPasswordless, useAuthonWeb3, useUser };
|
package/dist/index.js
CHANGED
|
@@ -480,26 +480,30 @@ function AuthonProvider({ children, storage, ...config }) {
|
|
|
480
480
|
};
|
|
481
481
|
}, []);
|
|
482
482
|
const signIn = useCallback(async (params) => {
|
|
483
|
-
const
|
|
484
|
-
|
|
483
|
+
const result = await client.signIn(params);
|
|
484
|
+
if ("needsVerification" in result || "mfaRequired" in result) return result;
|
|
485
|
+
setUser(result.user);
|
|
485
486
|
setAuthState({
|
|
486
487
|
isLoaded: true,
|
|
487
488
|
isSignedIn: true,
|
|
488
|
-
userId:
|
|
489
|
+
userId: result.user?.id || null,
|
|
489
490
|
sessionId: null,
|
|
490
|
-
accessToken: tokens.accessToken
|
|
491
|
+
accessToken: result.tokens.accessToken
|
|
491
492
|
});
|
|
493
|
+
return result;
|
|
492
494
|
}, [client]);
|
|
493
495
|
const signUp = useCallback(async (params) => {
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
+
const result = await client.signUp(params);
|
|
497
|
+
if ("needsVerification" in result) return result;
|
|
498
|
+
setUser(result.user);
|
|
496
499
|
setAuthState({
|
|
497
500
|
isLoaded: true,
|
|
498
501
|
isSignedIn: true,
|
|
499
|
-
userId:
|
|
502
|
+
userId: result.user?.id || null,
|
|
500
503
|
sessionId: null,
|
|
501
|
-
accessToken: tokens.accessToken
|
|
504
|
+
accessToken: result.tokens.accessToken
|
|
502
505
|
});
|
|
506
|
+
return result;
|
|
503
507
|
}, [client]);
|
|
504
508
|
const signOut = useCallback(async () => {
|
|
505
509
|
await client.signOut();
|