@fonderie/react-native-auth 0.1.0 → 0.2.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.
- package/README.md +23 -4
- package/dist/index.cjs +73 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +37 -23
- package/dist/index.js.map +1 -1
- package/package.json +12 -9
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
React Native hooks for Fonderie auth — `useLogin`, `useRegister`,
|
|
4
4
|
`useSession`, `useLogout`, `useForgotPassword`, `useResetPassword`, and
|
|
5
5
|
`useVerifyEmail`. Same shape as
|
|
6
|
-
[`@fonderie/react-auth`](https://github.com/
|
|
6
|
+
[`@fonderie/react-auth`](https://github.com/fonderiejs/sdk/tree/main/packages/react-auth),
|
|
7
7
|
with the access token persisted to `AsyncStorage` instead of `localStorage`.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
@@ -12,6 +12,25 @@ with the access token persisted to `AsyncStorage` instead of `localStorage`.
|
|
|
12
12
|
npm install @fonderie/react-native-auth @react-native-async-storage/async-storage
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## One client at the root (recommended)
|
|
16
|
+
|
|
17
|
+
Wrap your app in `FonderieProvider` from [`@fonderie/react`](../react) once and
|
|
18
|
+
every hook resolves the client from context — no client argument at call sites:
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { FonderieProvider } from "@fonderie/react";
|
|
22
|
+
|
|
23
|
+
<FonderieProvider client={client}>
|
|
24
|
+
<App />
|
|
25
|
+
</FonderieProvider>;
|
|
26
|
+
|
|
27
|
+
// anywhere below it:
|
|
28
|
+
const { ...state } = useLogin();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Passing a client explicitly (as below) still works everywhere and takes
|
|
32
|
+
precedence over context — handy in tests and multi-client apps.
|
|
33
|
+
|
|
15
34
|
## Use
|
|
16
35
|
|
|
17
36
|
```tsx
|
|
@@ -43,14 +62,14 @@ The access token is persisted to `AsyncStorage` and restored automatically by
|
|
|
43
62
|
`useSession` on mount; don't re-implement that in app code.
|
|
44
63
|
|
|
45
64
|
Want pre-built screens instead of wiring your own form?
|
|
46
|
-
See [`@fonderie/react-native-auth-screens`](https://github.com/
|
|
65
|
+
See [`@fonderie/react-native-auth-screens`](https://github.com/fonderiejs/sdk/tree/main/packages/react-native-auth-screens).
|
|
47
66
|
|
|
48
67
|
## Why this exists
|
|
49
68
|
|
|
50
69
|
You've shipped this plumbing before — auth, teams, billing, messaging —
|
|
51
70
|
and the next project will ask for it again. Fonderie packages it once:
|
|
52
71
|
plain TypeScript modules for
|
|
53
|
-
[`@fonderie/core`](https://github.com/
|
|
72
|
+
[`@fonderie/core`](https://github.com/fonderiejs/sdk/tree/main/packages/core),
|
|
54
73
|
PostgreSQL-backed, self-hosted, MIT. No external control plane, no
|
|
55
74
|
per-seat anything. Register the modules you need; skip the ones you don't.
|
|
56
75
|
|
|
@@ -59,7 +78,7 @@ around `@fonderie/client`, nothing more. No business logic lives here; it
|
|
|
59
78
|
lives in `@fonderie/auth` on the server.
|
|
60
79
|
|
|
61
80
|
Browse the whole set at
|
|
62
|
-
[
|
|
81
|
+
[fonderiejs/sdk](https://github.com/fonderiejs/sdk) · follow
|
|
63
82
|
[@fonderiejs](https://x.com/fonderiejs)
|
|
64
83
|
|
|
65
84
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -44,17 +44,19 @@ var import_client7 = require("@fonderie/client");
|
|
|
44
44
|
|
|
45
45
|
// src/hooks/useForgotPassword.ts
|
|
46
46
|
var import_client = require("@fonderie/client");
|
|
47
|
-
var import_react = require("react");
|
|
47
|
+
var import_react = require("@fonderie/react");
|
|
48
|
+
var import_react2 = require("react");
|
|
48
49
|
function useForgotPassword(client) {
|
|
49
|
-
const
|
|
50
|
-
const [
|
|
51
|
-
const [
|
|
52
|
-
const
|
|
50
|
+
const auth = (0, import_react.useFonderieSubClient)(client, (c) => c.auth, "useForgotPassword");
|
|
51
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
52
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
53
|
+
const [sent, setSent] = (0, import_react2.useState)(false);
|
|
54
|
+
const forgotPassword = (0, import_react2.useCallback)(
|
|
53
55
|
async (email) => {
|
|
54
56
|
setIsLoading(true);
|
|
55
57
|
setError(null);
|
|
56
58
|
try {
|
|
57
|
-
await
|
|
59
|
+
await auth.forgotPassword(email);
|
|
58
60
|
setSent(true);
|
|
59
61
|
} catch (err) {
|
|
60
62
|
const apiError = err instanceof import_client.FonderieApiError ? err : new import_client.FonderieApiError("unknown", String(err), 0);
|
|
@@ -64,14 +66,15 @@ function useForgotPassword(client) {
|
|
|
64
66
|
setIsLoading(false);
|
|
65
67
|
}
|
|
66
68
|
},
|
|
67
|
-
[
|
|
69
|
+
[auth]
|
|
68
70
|
);
|
|
69
71
|
return { forgotPassword, isLoading, error, sent };
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
// src/hooks/useLogin.ts
|
|
73
75
|
var import_client2 = require("@fonderie/client");
|
|
74
|
-
var
|
|
76
|
+
var import_react3 = require("@fonderie/react");
|
|
77
|
+
var import_react4 = require("react");
|
|
75
78
|
|
|
76
79
|
// src/storage.ts
|
|
77
80
|
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"), 1);
|
|
@@ -88,16 +91,17 @@ function readToken() {
|
|
|
88
91
|
|
|
89
92
|
// src/hooks/useLogin.ts
|
|
90
93
|
function useLogin(client) {
|
|
91
|
-
const
|
|
92
|
-
const [
|
|
93
|
-
const [
|
|
94
|
-
const
|
|
94
|
+
const auth = (0, import_react3.useFonderieSubClient)(client, (c) => c.auth, "useLogin");
|
|
95
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
96
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
97
|
+
const [data, setData] = (0, import_react4.useState)(null);
|
|
98
|
+
const login = (0, import_react4.useCallback)(
|
|
95
99
|
async (input) => {
|
|
96
100
|
setIsLoading(true);
|
|
97
101
|
setError(null);
|
|
98
102
|
try {
|
|
99
|
-
const { result } = await
|
|
100
|
-
|
|
103
|
+
const { result } = await auth.login(input);
|
|
104
|
+
auth.setAccessToken(result.tokens.access);
|
|
101
105
|
await persistToken(result.tokens.access);
|
|
102
106
|
setData(result);
|
|
103
107
|
return result;
|
|
@@ -109,48 +113,52 @@ function useLogin(client) {
|
|
|
109
113
|
setIsLoading(false);
|
|
110
114
|
}
|
|
111
115
|
},
|
|
112
|
-
[
|
|
116
|
+
[auth]
|
|
113
117
|
);
|
|
114
118
|
return { login, isLoading, error, data };
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
// src/hooks/useLogout.ts
|
|
118
122
|
var import_client3 = require("@fonderie/client");
|
|
119
|
-
var
|
|
123
|
+
var import_react5 = require("@fonderie/react");
|
|
124
|
+
var import_react6 = require("react");
|
|
120
125
|
function useLogout(client) {
|
|
121
|
-
const
|
|
122
|
-
const [
|
|
123
|
-
const
|
|
126
|
+
const auth = (0, import_react5.useFonderieSubClient)(client, (c) => c.auth, "useLogout");
|
|
127
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
128
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
129
|
+
const logout = (0, import_react6.useCallback)(async () => {
|
|
124
130
|
setIsLoading(true);
|
|
125
131
|
setError(null);
|
|
126
132
|
try {
|
|
127
|
-
await
|
|
133
|
+
await auth.logout();
|
|
128
134
|
} catch (err) {
|
|
129
135
|
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
130
136
|
setError(apiError);
|
|
131
137
|
} finally {
|
|
132
|
-
|
|
138
|
+
auth.setAccessToken(void 0);
|
|
133
139
|
await clearToken();
|
|
134
140
|
setIsLoading(false);
|
|
135
141
|
}
|
|
136
|
-
}, [
|
|
142
|
+
}, [auth]);
|
|
137
143
|
return { logout, isLoading, error };
|
|
138
144
|
}
|
|
139
145
|
|
|
140
146
|
// src/hooks/useRegister.ts
|
|
141
147
|
var import_client4 = require("@fonderie/client");
|
|
142
|
-
var
|
|
148
|
+
var import_react7 = require("@fonderie/react");
|
|
149
|
+
var import_react8 = require("react");
|
|
143
150
|
function useRegister(client) {
|
|
144
|
-
const
|
|
145
|
-
const [
|
|
146
|
-
const [
|
|
147
|
-
const
|
|
151
|
+
const auth = (0, import_react7.useFonderieSubClient)(client, (c) => c.auth, "useRegister");
|
|
152
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
153
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
154
|
+
const [data, setData] = (0, import_react8.useState)(null);
|
|
155
|
+
const register = (0, import_react8.useCallback)(
|
|
148
156
|
async (input) => {
|
|
149
157
|
setIsLoading(true);
|
|
150
158
|
setError(null);
|
|
151
159
|
try {
|
|
152
|
-
const { result } = await
|
|
153
|
-
|
|
160
|
+
const { result } = await auth.register(input);
|
|
161
|
+
auth.setAccessToken(result.tokens.access);
|
|
154
162
|
await persistToken(result.tokens.access);
|
|
155
163
|
setData(result);
|
|
156
164
|
return result;
|
|
@@ -162,24 +170,26 @@ function useRegister(client) {
|
|
|
162
170
|
setIsLoading(false);
|
|
163
171
|
}
|
|
164
172
|
},
|
|
165
|
-
[
|
|
173
|
+
[auth]
|
|
166
174
|
);
|
|
167
175
|
return { register, isLoading, error, data };
|
|
168
176
|
}
|
|
169
177
|
|
|
170
178
|
// src/hooks/useResetPassword.ts
|
|
171
179
|
var import_client5 = require("@fonderie/client");
|
|
172
|
-
var
|
|
180
|
+
var import_react9 = require("@fonderie/react");
|
|
181
|
+
var import_react10 = require("react");
|
|
173
182
|
function useResetPassword(client) {
|
|
174
|
-
const
|
|
175
|
-
const [
|
|
176
|
-
const [
|
|
177
|
-
const
|
|
183
|
+
const auth = (0, import_react9.useFonderieSubClient)(client, (c) => c.auth, "useResetPassword");
|
|
184
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
185
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
186
|
+
const [done, setDone] = (0, import_react10.useState)(false);
|
|
187
|
+
const resetPassword = (0, import_react10.useCallback)(
|
|
178
188
|
async (input) => {
|
|
179
189
|
setIsLoading(true);
|
|
180
190
|
setError(null);
|
|
181
191
|
try {
|
|
182
|
-
await
|
|
192
|
+
await auth.resetPassword(input);
|
|
183
193
|
setDone(true);
|
|
184
194
|
} catch (err) {
|
|
185
195
|
const apiError = err instanceof import_client5.FonderieApiError ? err : new import_client5.FonderieApiError("unknown", String(err), 0);
|
|
@@ -189,64 +199,68 @@ function useResetPassword(client) {
|
|
|
189
199
|
setIsLoading(false);
|
|
190
200
|
}
|
|
191
201
|
},
|
|
192
|
-
[
|
|
202
|
+
[auth]
|
|
193
203
|
);
|
|
194
204
|
return { resetPassword, isLoading, error, done };
|
|
195
205
|
}
|
|
196
206
|
|
|
197
207
|
// src/hooks/useSession.ts
|
|
198
|
-
var
|
|
208
|
+
var import_react11 = require("@fonderie/react");
|
|
209
|
+
var import_react12 = require("react");
|
|
199
210
|
function useSession(client) {
|
|
200
|
-
const
|
|
201
|
-
const [
|
|
202
|
-
const [
|
|
203
|
-
const
|
|
211
|
+
const auth = (0, import_react11.useFonderieSubClient)(client, (c) => c.auth, "useSession");
|
|
212
|
+
const [user, setUser] = (0, import_react12.useState)(null);
|
|
213
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(true);
|
|
214
|
+
const [isAuthenticated, setIsAuthenticated] = (0, import_react12.useState)(false);
|
|
215
|
+
const refresh = (0, import_react12.useCallback)(async () => {
|
|
204
216
|
setIsLoading(true);
|
|
205
217
|
try {
|
|
206
|
-
const { result } = await
|
|
218
|
+
const { result } = await auth.getUser();
|
|
207
219
|
setUser(result.user);
|
|
208
220
|
setIsAuthenticated(true);
|
|
209
221
|
} catch {
|
|
210
222
|
setUser(null);
|
|
211
223
|
setIsAuthenticated(false);
|
|
212
|
-
|
|
224
|
+
auth.setAccessToken(void 0);
|
|
213
225
|
await clearToken();
|
|
214
226
|
} finally {
|
|
215
227
|
setIsLoading(false);
|
|
216
228
|
}
|
|
217
|
-
}, [
|
|
218
|
-
const logout = (0,
|
|
229
|
+
}, [auth]);
|
|
230
|
+
const logout = (0, import_react12.useCallback)(async () => {
|
|
219
231
|
try {
|
|
220
|
-
await
|
|
232
|
+
await auth.logout();
|
|
221
233
|
} catch {
|
|
222
234
|
}
|
|
223
|
-
|
|
235
|
+
auth.setAccessToken(void 0);
|
|
224
236
|
await clearToken();
|
|
225
237
|
setUser(null);
|
|
226
238
|
setIsAuthenticated(false);
|
|
227
|
-
}, [
|
|
228
|
-
(0,
|
|
239
|
+
}, [auth]);
|
|
240
|
+
(0, import_react12.useEffect)(() => {
|
|
229
241
|
readToken().then((token) => {
|
|
230
|
-
if (token)
|
|
242
|
+
if (token) auth.setAccessToken(token);
|
|
231
243
|
void refresh();
|
|
232
244
|
});
|
|
233
|
-
}, [
|
|
245
|
+
}, [auth, refresh]);
|
|
234
246
|
return { user, isLoading, isAuthenticated, refresh, logout };
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
// src/hooks/useVerifyEmail.ts
|
|
238
250
|
var import_client6 = require("@fonderie/client");
|
|
239
|
-
var
|
|
251
|
+
var import_react13 = require("@fonderie/react");
|
|
252
|
+
var import_react14 = require("react");
|
|
240
253
|
function useVerifyEmail(client) {
|
|
241
|
-
const
|
|
242
|
-
const [
|
|
243
|
-
const [
|
|
244
|
-
const
|
|
254
|
+
const auth = (0, import_react13.useFonderieSubClient)(client, (c) => c.auth, "useVerifyEmail");
|
|
255
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
|
|
256
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
257
|
+
const [data, setData] = (0, import_react14.useState)(null);
|
|
258
|
+
const verifyEmail = (0, import_react14.useCallback)(
|
|
245
259
|
async (pin) => {
|
|
246
260
|
setIsLoading(true);
|
|
247
261
|
setError(null);
|
|
248
262
|
try {
|
|
249
|
-
const { result } = await
|
|
263
|
+
const { result } = await auth.verifyEmail(pin);
|
|
250
264
|
setData(result);
|
|
251
265
|
return result;
|
|
252
266
|
} catch (err) {
|
|
@@ -257,7 +271,7 @@ function useVerifyEmail(client) {
|
|
|
257
271
|
setIsLoading(false);
|
|
258
272
|
}
|
|
259
273
|
},
|
|
260
|
-
[
|
|
274
|
+
[auth]
|
|
261
275
|
);
|
|
262
276
|
return { verifyEmail, isLoading, error, data };
|
|
263
277
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useForgotPassword.ts","../src/hooks/useLogin.ts","../src/storage.ts","../src/hooks/useLogout.ts","../src/hooks/useRegister.ts","../src/hooks/useResetPassword.ts","../src/hooks/useSession.ts","../src/hooks/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseForgotPasswordReturn,\n\tIUseLoginReturn,\n\tIUseLogoutReturn,\n\tIUseRegisterReturn,\n\tIUseResetPasswordReturn,\n\tIUseSessionReturn,\n\tIUseVerifyEmailReturn,\n} from './hooks';\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './hooks';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseForgotPasswordReturn {\n\tforgotPassword: (email: string) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tsent: boolean;\n}\n\nexport function useForgotPassword(client: AuthClient): IUseForgotPasswordReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [sent, setSent] = useState(false);\n\n\tconst forgotPassword = useCallback(\n\t\tasync (email: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.forgotPassword(email);\n\t\t\t\tsetSent(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseLoginReturn {\n\tlogin: (input: ILoginInput) => Promise<ILoginResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: ILoginResult | null;\n}\n\nexport function useLogin(client: AuthClient): IUseLoginReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<ILoginResult | null>(null);\n\n\tconst login = useCallback(\n\t\tasync (input: ILoginInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.login(input);\n\t\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { login, isLoading, error, data };\n}\n","import AsyncStorage from '@react-native-async-storage/async-storage';\n\nexport const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\treturn AsyncStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\treturn AsyncStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken() {\n\treturn AsyncStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\nimport { clearToken } from '../storage';\n\nexport interface IUseLogoutReturn {\n\tlogout: () => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useLogout(client: AuthClient): IUseLogoutReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst logout = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseRegisterReturn {\n\tregister: (input: IRegisterInput) => Promise<IRegisterResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IRegisterResult | null;\n}\n\nexport function useRegister(client: AuthClient): IUseRegisterReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IRegisterResult | null>(null);\n\n\tconst register = useCallback(\n\t\tasync (input: IRegisterInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.register(input);\n\t\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseResetPasswordReturn {\n\tresetPassword: (input: IResetPasswordInput) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdone: boolean;\n}\n\nexport function useResetPassword(client: AuthClient): IUseResetPasswordReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [done, setDone] = useState(false);\n\n\tconst resetPassword = useCallback(\n\t\tasync (input: IResetPasswordInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.resetPassword(input);\n\t\t\t\tsetDone(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { clearToken, readToken } from '../storage';\n\nexport interface IUseSessionReturn {\n\tuser: IUserDTO | null;\n\tisLoading: boolean;\n\tisAuthenticated: boolean;\n\trefresh: () => Promise<void>;\n\tlogout: () => Promise<void>;\n}\n\nexport function useSession(client: AuthClient): IUseSessionReturn {\n\tconst [user, setUser] = useState<IUserDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [isAuthenticated, setIsAuthenticated] = useState(false);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\ttry {\n\t\t\tconst { result } = await client.getUser();\n\t\t\tsetUser(result.user);\n\t\t\tsetIsAuthenticated(true);\n\t\t} catch {\n\t\t\tsetUser(null);\n\t\t\tsetIsAuthenticated(false);\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tconst logout = useCallback(async () => {\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tclient.setAccessToken(undefined);\n\t\tawait clearToken();\n\t\tsetUser(null);\n\t\tsetIsAuthenticated(false);\n\t}, [client]);\n\n\tuseEffect(() => {\n\t\treadToken().then((token) => {\n\t\t\tif (token) client.setAccessToken(token);\n\t\t\tvoid refresh();\n\t\t});\n\t}, [client, refresh]);\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseVerifyEmailReturn {\n\tverifyEmail: (pin: string) => Promise<IVerifyEmailResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IVerifyEmailResult | null;\n}\n\nexport function useVerifyEmail(client: AuthClient): IUseVerifyEmailReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IVerifyEmailResult | null>(null);\n\n\tconst verifyEmail = useCallback(\n\t\tasync (pin: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.verifyEmail(pin);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,IAAAA,iBAAiC;;;ACXjC,oBAAiC;AACjC,mBAAsC;AAS/B,SAAS,kBAAkB,QAA8C;AAC/E,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAkC,IAAI;AAChE,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,KAAK;AAEtC,QAAM,qBAAiB;AAAA,IACtB,OAAO,UAAkB;AACxB,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,OAAO,eAAe,KAAK;AACjC,gBAAQ,IAAI;AAAA,MACb,SAAS,KAAK;AACb,cAAM,WACL,eAAe,iCAAmB,MAAM,IAAI,+BAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA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WAAO,eAAe,MAAS;AAC/B,UAAM,WAAW;AACjB,YAAQ,IAAI;AACZ,uBAAmB,KAAK;AAAA,EACzB,GAAG,CAAC,MAAM,CAAC;AAEX,+BAAU,MAAM;AACf,cAAU,EAAE,KAAK,CAAC,UAAU;AAC3B,UAAI,MAAO,QAAO,eAAe,KAAK;AACtC,WAAK,QAAQ;AAAA,IACd,CAAC;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,CAAC;AAEpB,SAAO,EAAE,MAAM,WAAW,iBAAiB,SAAS,OAAO;AAC5D;;;ACpDA,IAAAC,iBAAiC;AACjC,IAAAC,gBAAsC;AAS/B,SAAS,eAAe,QAA2C;AACzE,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,IAAI;AAChE,QAAM,CAAC,MAAM,OAAO,QAAI,wBAAoC,IAAI;AAEhE,QAAM,kBAAc;AAAA,IACnB,OAAO,QAAgB;AACtB,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,OAAO,YAAY,GAAG;AAC/C,gBAAQ,MAAM;AACd,eAAO;AAAA,MACR,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["import_client","import_client","import_react","AsyncStorage","import_client","import_react","import_client","import_react","import_client","import_react","import_react","import_client","import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/useForgotPassword.ts","../src/hooks/useLogin.ts","../src/storage.ts","../src/hooks/useLogout.ts","../src/hooks/useRegister.ts","../src/hooks/useResetPassword.ts","../src/hooks/useSession.ts","../src/hooks/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseForgotPasswordReturn,\n\tIUseLoginReturn,\n\tIUseLogoutReturn,\n\tIUseRegisterReturn,\n\tIUseResetPasswordReturn,\n\tIUseSessionReturn,\n\tIUseVerifyEmailReturn,\n} from './hooks';\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './hooks';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseForgotPasswordReturn {\n\tforgotPassword: (email: string) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tsent: boolean;\n}\n\nexport function useForgotPassword(client?: AuthClient): IUseForgotPasswordReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useForgotPassword');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [sent, setSent] = useState(false);\n\n\tconst forgotPassword = useCallback(\n\t\tasync (email: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait auth.forgotPassword(email);\n\t\t\t\tsetSent(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseLoginReturn {\n\tlogin: (input: ILoginInput) => Promise<ILoginResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: ILoginResult | null;\n}\n\nexport function useLogin(client?: AuthClient): IUseLoginReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogin');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<ILoginResult | null>(null);\n\n\tconst login = useCallback(\n\t\tasync (input: ILoginInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.login(input);\n\t\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { login, isLoading, error, data };\n}\n","import AsyncStorage from '@react-native-async-storage/async-storage';\n\nexport const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\treturn AsyncStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\treturn AsyncStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken() {\n\treturn AsyncStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\nimport { clearToken } from '../storage';\n\nexport interface IUseLogoutReturn {\n\tlogout: () => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useLogout(client?: AuthClient): IUseLogoutReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst logout = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tawait auth.logout();\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [auth]);\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseRegisterReturn {\n\tregister: (input: IRegisterInput) => Promise<IRegisterResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IRegisterResult | null;\n}\n\nexport function useRegister(client?: AuthClient): IUseRegisterReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useRegister');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IRegisterResult | null>(null);\n\n\tconst register = useCallback(\n\t\tasync (input: IRegisterInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.register(input);\n\t\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseResetPasswordReturn {\n\tresetPassword: (input: IResetPasswordInput) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdone: boolean;\n}\n\nexport function useResetPassword(client?: AuthClient): IUseResetPasswordReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useResetPassword');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [done, setDone] = useState(false);\n\n\tconst resetPassword = useCallback(\n\t\tasync (input: IResetPasswordInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait auth.resetPassword(input);\n\t\t\t\tsetDone(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\nimport { clearToken, readToken } from '../storage';\n\nexport interface IUseSessionReturn {\n\tuser: IUserDTO | null;\n\tisLoading: boolean;\n\tisAuthenticated: boolean;\n\trefresh: () => Promise<void>;\n\tlogout: () => Promise<void>;\n}\n\nexport function useSession(client?: AuthClient): IUseSessionReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useSession');\n\tconst [user, setUser] = useState<IUserDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [isAuthenticated, setIsAuthenticated] = useState(false);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\ttry {\n\t\t\tconst { result } = await auth.getUser();\n\t\t\tsetUser(result.user);\n\t\t\tsetIsAuthenticated(true);\n\t\t} catch {\n\t\t\tsetUser(null);\n\t\t\tsetIsAuthenticated(false);\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [auth]);\n\n\tconst logout = useCallback(async () => {\n\t\ttry {\n\t\t\tawait auth.logout();\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tauth.setAccessToken(undefined);\n\t\tawait clearToken();\n\t\tsetUser(null);\n\t\tsetIsAuthenticated(false);\n\t}, [auth]);\n\n\tuseEffect(() => {\n\t\treadToken().then((token) => {\n\t\t\tif (token) auth.setAccessToken(token);\n\t\t\tvoid refresh();\n\t\t});\n\t}, [auth, refresh]);\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseVerifyEmailReturn {\n\tverifyEmail: (pin: string) => Promise<IVerifyEmailResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IVerifyEmailResult | null;\n}\n\nexport function useVerifyEmail(client?: AuthClient): IUseVerifyEmailReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useVerifyEmail');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IVerifyEmailResult | null>(null);\n\n\tconst verifyEmail = useCallback(\n\t\tasync (pin: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.verifyEmail(pin);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,IAAAA,iBAAiC;;;ACXjC,oBAAiC;AACjC,mBAAqC;AACrC,IAAAC,gBAAsC;AAS/B,SAAS,kBAAkB,QAA+C;AAChF,QAAM,WAAO,mCAAqB,QAAQ,CAAC,MAAM,EAAE,MAAM,mBAAmB;AAC5E,QAAM,CAAC,WAAW,YAAY,QAAI,wBAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,IAAI;AAChE,QAAM,CAAC,MAAM,OAAO,QAAI,wBAAS,KAAK;AAEtC,QAAM,qBAAiB;AAAA,IACtB,OAAO,UAAkB;AACxB,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,KAAK,eAAe,KAAK;AAC/B,gBAAQ,IAAI;AAAA,MACb,SAAS,KAAK;AACb,cAAM,WACL,eAAe,iCAAmB,MAAM,IAAI,+BAAiB,WAAW,OAAO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O,QAAgB;AACtB,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,KAAK,YAAY,GAAG;AAC7C,gBAAQ,MAAM;AACd,eAAO;AAAA,MACR,SAAS,KAAK;AACb,cAAM,WACL,eAAe,kCAAmB,MAAM,IAAI,gCAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,IAAI;AAAA,EACN;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["import_client","import_react","import_client","import_react","AsyncStorage","import_client","import_react","import_client","import_react","import_client","import_react","import_react","import_client","import_react"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -7,7 +7,7 @@ interface IUseForgotPasswordReturn {
|
|
|
7
7
|
error: FonderieApiError | null;
|
|
8
8
|
sent: boolean;
|
|
9
9
|
}
|
|
10
|
-
declare function useForgotPassword(client
|
|
10
|
+
declare function useForgotPassword(client?: AuthClient): IUseForgotPasswordReturn;
|
|
11
11
|
|
|
12
12
|
interface IUseLoginReturn {
|
|
13
13
|
login: (input: ILoginInput) => Promise<ILoginResult>;
|
|
@@ -15,14 +15,14 @@ interface IUseLoginReturn {
|
|
|
15
15
|
error: FonderieApiError | null;
|
|
16
16
|
data: ILoginResult | null;
|
|
17
17
|
}
|
|
18
|
-
declare function useLogin(client
|
|
18
|
+
declare function useLogin(client?: AuthClient): IUseLoginReturn;
|
|
19
19
|
|
|
20
20
|
interface IUseLogoutReturn {
|
|
21
21
|
logout: () => Promise<void>;
|
|
22
22
|
isLoading: boolean;
|
|
23
23
|
error: FonderieApiError | null;
|
|
24
24
|
}
|
|
25
|
-
declare function useLogout(client
|
|
25
|
+
declare function useLogout(client?: AuthClient): IUseLogoutReturn;
|
|
26
26
|
|
|
27
27
|
interface IUseRegisterReturn {
|
|
28
28
|
register: (input: IRegisterInput) => Promise<IRegisterResult>;
|
|
@@ -30,7 +30,7 @@ interface IUseRegisterReturn {
|
|
|
30
30
|
error: FonderieApiError | null;
|
|
31
31
|
data: IRegisterResult | null;
|
|
32
32
|
}
|
|
33
|
-
declare function useRegister(client
|
|
33
|
+
declare function useRegister(client?: AuthClient): IUseRegisterReturn;
|
|
34
34
|
|
|
35
35
|
interface IUseResetPasswordReturn {
|
|
36
36
|
resetPassword: (input: IResetPasswordInput) => Promise<void>;
|
|
@@ -38,7 +38,7 @@ interface IUseResetPasswordReturn {
|
|
|
38
38
|
error: FonderieApiError | null;
|
|
39
39
|
done: boolean;
|
|
40
40
|
}
|
|
41
|
-
declare function useResetPassword(client
|
|
41
|
+
declare function useResetPassword(client?: AuthClient): IUseResetPasswordReturn;
|
|
42
42
|
|
|
43
43
|
interface IUseSessionReturn {
|
|
44
44
|
user: IUserDTO | null;
|
|
@@ -47,7 +47,7 @@ interface IUseSessionReturn {
|
|
|
47
47
|
refresh: () => Promise<void>;
|
|
48
48
|
logout: () => Promise<void>;
|
|
49
49
|
}
|
|
50
|
-
declare function useSession(client
|
|
50
|
+
declare function useSession(client?: AuthClient): IUseSessionReturn;
|
|
51
51
|
|
|
52
52
|
interface IUseVerifyEmailReturn {
|
|
53
53
|
verifyEmail: (pin: string) => Promise<IVerifyEmailResult>;
|
|
@@ -55,6 +55,6 @@ interface IUseVerifyEmailReturn {
|
|
|
55
55
|
error: FonderieApiError | null;
|
|
56
56
|
data: IVerifyEmailResult | null;
|
|
57
57
|
}
|
|
58
|
-
declare function useVerifyEmail(client
|
|
58
|
+
declare function useVerifyEmail(client?: AuthClient): IUseVerifyEmailReturn;
|
|
59
59
|
|
|
60
60
|
export { type IUseForgotPasswordReturn, type IUseLoginReturn, type IUseLogoutReturn, type IUseRegisterReturn, type IUseResetPasswordReturn, type IUseSessionReturn, type IUseVerifyEmailReturn, useForgotPassword, useLogin, useLogout, useRegister, useResetPassword, useSession, useVerifyEmail };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ interface IUseForgotPasswordReturn {
|
|
|
7
7
|
error: FonderieApiError | null;
|
|
8
8
|
sent: boolean;
|
|
9
9
|
}
|
|
10
|
-
declare function useForgotPassword(client
|
|
10
|
+
declare function useForgotPassword(client?: AuthClient): IUseForgotPasswordReturn;
|
|
11
11
|
|
|
12
12
|
interface IUseLoginReturn {
|
|
13
13
|
login: (input: ILoginInput) => Promise<ILoginResult>;
|
|
@@ -15,14 +15,14 @@ interface IUseLoginReturn {
|
|
|
15
15
|
error: FonderieApiError | null;
|
|
16
16
|
data: ILoginResult | null;
|
|
17
17
|
}
|
|
18
|
-
declare function useLogin(client
|
|
18
|
+
declare function useLogin(client?: AuthClient): IUseLoginReturn;
|
|
19
19
|
|
|
20
20
|
interface IUseLogoutReturn {
|
|
21
21
|
logout: () => Promise<void>;
|
|
22
22
|
isLoading: boolean;
|
|
23
23
|
error: FonderieApiError | null;
|
|
24
24
|
}
|
|
25
|
-
declare function useLogout(client
|
|
25
|
+
declare function useLogout(client?: AuthClient): IUseLogoutReturn;
|
|
26
26
|
|
|
27
27
|
interface IUseRegisterReturn {
|
|
28
28
|
register: (input: IRegisterInput) => Promise<IRegisterResult>;
|
|
@@ -30,7 +30,7 @@ interface IUseRegisterReturn {
|
|
|
30
30
|
error: FonderieApiError | null;
|
|
31
31
|
data: IRegisterResult | null;
|
|
32
32
|
}
|
|
33
|
-
declare function useRegister(client
|
|
33
|
+
declare function useRegister(client?: AuthClient): IUseRegisterReturn;
|
|
34
34
|
|
|
35
35
|
interface IUseResetPasswordReturn {
|
|
36
36
|
resetPassword: (input: IResetPasswordInput) => Promise<void>;
|
|
@@ -38,7 +38,7 @@ interface IUseResetPasswordReturn {
|
|
|
38
38
|
error: FonderieApiError | null;
|
|
39
39
|
done: boolean;
|
|
40
40
|
}
|
|
41
|
-
declare function useResetPassword(client
|
|
41
|
+
declare function useResetPassword(client?: AuthClient): IUseResetPasswordReturn;
|
|
42
42
|
|
|
43
43
|
interface IUseSessionReturn {
|
|
44
44
|
user: IUserDTO | null;
|
|
@@ -47,7 +47,7 @@ interface IUseSessionReturn {
|
|
|
47
47
|
refresh: () => Promise<void>;
|
|
48
48
|
logout: () => Promise<void>;
|
|
49
49
|
}
|
|
50
|
-
declare function useSession(client
|
|
50
|
+
declare function useSession(client?: AuthClient): IUseSessionReturn;
|
|
51
51
|
|
|
52
52
|
interface IUseVerifyEmailReturn {
|
|
53
53
|
verifyEmail: (pin: string) => Promise<IVerifyEmailResult>;
|
|
@@ -55,6 +55,6 @@ interface IUseVerifyEmailReturn {
|
|
|
55
55
|
error: FonderieApiError | null;
|
|
56
56
|
data: IVerifyEmailResult | null;
|
|
57
57
|
}
|
|
58
|
-
declare function useVerifyEmail(client
|
|
58
|
+
declare function useVerifyEmail(client?: AuthClient): IUseVerifyEmailReturn;
|
|
59
59
|
|
|
60
60
|
export { type IUseForgotPasswordReturn, type IUseLoginReturn, type IUseLogoutReturn, type IUseRegisterReturn, type IUseResetPasswordReturn, type IUseSessionReturn, type IUseVerifyEmailReturn, useForgotPassword, useLogin, useLogout, useRegister, useResetPassword, useSession, useVerifyEmail };
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,10 @@ import { FonderieApiError as FonderieApiError7 } from "@fonderie/client";
|
|
|
3
3
|
|
|
4
4
|
// src/hooks/useForgotPassword.ts
|
|
5
5
|
import { FonderieApiError } from "@fonderie/client";
|
|
6
|
+
import { useFonderieSubClient } from "@fonderie/react";
|
|
6
7
|
import { useCallback, useState } from "react";
|
|
7
8
|
function useForgotPassword(client) {
|
|
9
|
+
const auth = useFonderieSubClient(client, (c) => c.auth, "useForgotPassword");
|
|
8
10
|
const [isLoading, setIsLoading] = useState(false);
|
|
9
11
|
const [error, setError] = useState(null);
|
|
10
12
|
const [sent, setSent] = useState(false);
|
|
@@ -13,7 +15,7 @@ function useForgotPassword(client) {
|
|
|
13
15
|
setIsLoading(true);
|
|
14
16
|
setError(null);
|
|
15
17
|
try {
|
|
16
|
-
await
|
|
18
|
+
await auth.forgotPassword(email);
|
|
17
19
|
setSent(true);
|
|
18
20
|
} catch (err) {
|
|
19
21
|
const apiError = err instanceof FonderieApiError ? err : new FonderieApiError("unknown", String(err), 0);
|
|
@@ -23,13 +25,14 @@ function useForgotPassword(client) {
|
|
|
23
25
|
setIsLoading(false);
|
|
24
26
|
}
|
|
25
27
|
},
|
|
26
|
-
[
|
|
28
|
+
[auth]
|
|
27
29
|
);
|
|
28
30
|
return { forgotPassword, isLoading, error, sent };
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// src/hooks/useLogin.ts
|
|
32
34
|
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
35
|
+
import { useFonderieSubClient as useFonderieSubClient2 } from "@fonderie/react";
|
|
33
36
|
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
34
37
|
|
|
35
38
|
// src/storage.ts
|
|
@@ -47,6 +50,7 @@ function readToken() {
|
|
|
47
50
|
|
|
48
51
|
// src/hooks/useLogin.ts
|
|
49
52
|
function useLogin(client) {
|
|
53
|
+
const auth = useFonderieSubClient2(client, (c) => c.auth, "useLogin");
|
|
50
54
|
const [isLoading, setIsLoading] = useState2(false);
|
|
51
55
|
const [error, setError] = useState2(null);
|
|
52
56
|
const [data, setData] = useState2(null);
|
|
@@ -55,8 +59,8 @@ function useLogin(client) {
|
|
|
55
59
|
setIsLoading(true);
|
|
56
60
|
setError(null);
|
|
57
61
|
try {
|
|
58
|
-
const { result } = await
|
|
59
|
-
|
|
62
|
+
const { result } = await auth.login(input);
|
|
63
|
+
auth.setAccessToken(result.tokens.access);
|
|
60
64
|
await persistToken(result.tokens.access);
|
|
61
65
|
setData(result);
|
|
62
66
|
return result;
|
|
@@ -68,38 +72,42 @@ function useLogin(client) {
|
|
|
68
72
|
setIsLoading(false);
|
|
69
73
|
}
|
|
70
74
|
},
|
|
71
|
-
[
|
|
75
|
+
[auth]
|
|
72
76
|
);
|
|
73
77
|
return { login, isLoading, error, data };
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
// src/hooks/useLogout.ts
|
|
77
81
|
import { FonderieApiError as FonderieApiError3 } from "@fonderie/client";
|
|
82
|
+
import { useFonderieSubClient as useFonderieSubClient3 } from "@fonderie/react";
|
|
78
83
|
import { useCallback as useCallback3, useState as useState3 } from "react";
|
|
79
84
|
function useLogout(client) {
|
|
85
|
+
const auth = useFonderieSubClient3(client, (c) => c.auth, "useLogout");
|
|
80
86
|
const [isLoading, setIsLoading] = useState3(false);
|
|
81
87
|
const [error, setError] = useState3(null);
|
|
82
88
|
const logout = useCallback3(async () => {
|
|
83
89
|
setIsLoading(true);
|
|
84
90
|
setError(null);
|
|
85
91
|
try {
|
|
86
|
-
await
|
|
92
|
+
await auth.logout();
|
|
87
93
|
} catch (err) {
|
|
88
94
|
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
89
95
|
setError(apiError);
|
|
90
96
|
} finally {
|
|
91
|
-
|
|
97
|
+
auth.setAccessToken(void 0);
|
|
92
98
|
await clearToken();
|
|
93
99
|
setIsLoading(false);
|
|
94
100
|
}
|
|
95
|
-
}, [
|
|
101
|
+
}, [auth]);
|
|
96
102
|
return { logout, isLoading, error };
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
// src/hooks/useRegister.ts
|
|
100
106
|
import { FonderieApiError as FonderieApiError4 } from "@fonderie/client";
|
|
107
|
+
import { useFonderieSubClient as useFonderieSubClient4 } from "@fonderie/react";
|
|
101
108
|
import { useCallback as useCallback4, useState as useState4 } from "react";
|
|
102
109
|
function useRegister(client) {
|
|
110
|
+
const auth = useFonderieSubClient4(client, (c) => c.auth, "useRegister");
|
|
103
111
|
const [isLoading, setIsLoading] = useState4(false);
|
|
104
112
|
const [error, setError] = useState4(null);
|
|
105
113
|
const [data, setData] = useState4(null);
|
|
@@ -108,8 +116,8 @@ function useRegister(client) {
|
|
|
108
116
|
setIsLoading(true);
|
|
109
117
|
setError(null);
|
|
110
118
|
try {
|
|
111
|
-
const { result } = await
|
|
112
|
-
|
|
119
|
+
const { result } = await auth.register(input);
|
|
120
|
+
auth.setAccessToken(result.tokens.access);
|
|
113
121
|
await persistToken(result.tokens.access);
|
|
114
122
|
setData(result);
|
|
115
123
|
return result;
|
|
@@ -121,15 +129,17 @@ function useRegister(client) {
|
|
|
121
129
|
setIsLoading(false);
|
|
122
130
|
}
|
|
123
131
|
},
|
|
124
|
-
[
|
|
132
|
+
[auth]
|
|
125
133
|
);
|
|
126
134
|
return { register, isLoading, error, data };
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
// src/hooks/useResetPassword.ts
|
|
130
138
|
import { FonderieApiError as FonderieApiError5 } from "@fonderie/client";
|
|
139
|
+
import { useFonderieSubClient as useFonderieSubClient5 } from "@fonderie/react";
|
|
131
140
|
import { useCallback as useCallback5, useState as useState5 } from "react";
|
|
132
141
|
function useResetPassword(client) {
|
|
142
|
+
const auth = useFonderieSubClient5(client, (c) => c.auth, "useResetPassword");
|
|
133
143
|
const [isLoading, setIsLoading] = useState5(false);
|
|
134
144
|
const [error, setError] = useState5(null);
|
|
135
145
|
const [done, setDone] = useState5(false);
|
|
@@ -138,7 +148,7 @@ function useResetPassword(client) {
|
|
|
138
148
|
setIsLoading(true);
|
|
139
149
|
setError(null);
|
|
140
150
|
try {
|
|
141
|
-
await
|
|
151
|
+
await auth.resetPassword(input);
|
|
142
152
|
setDone(true);
|
|
143
153
|
} catch (err) {
|
|
144
154
|
const apiError = err instanceof FonderieApiError5 ? err : new FonderieApiError5("unknown", String(err), 0);
|
|
@@ -148,55 +158,59 @@ function useResetPassword(client) {
|
|
|
148
158
|
setIsLoading(false);
|
|
149
159
|
}
|
|
150
160
|
},
|
|
151
|
-
[
|
|
161
|
+
[auth]
|
|
152
162
|
);
|
|
153
163
|
return { resetPassword, isLoading, error, done };
|
|
154
164
|
}
|
|
155
165
|
|
|
156
166
|
// src/hooks/useSession.ts
|
|
167
|
+
import { useFonderieSubClient as useFonderieSubClient6 } from "@fonderie/react";
|
|
157
168
|
import { useCallback as useCallback6, useEffect, useState as useState6 } from "react";
|
|
158
169
|
function useSession(client) {
|
|
170
|
+
const auth = useFonderieSubClient6(client, (c) => c.auth, "useSession");
|
|
159
171
|
const [user, setUser] = useState6(null);
|
|
160
172
|
const [isLoading, setIsLoading] = useState6(true);
|
|
161
173
|
const [isAuthenticated, setIsAuthenticated] = useState6(false);
|
|
162
174
|
const refresh = useCallback6(async () => {
|
|
163
175
|
setIsLoading(true);
|
|
164
176
|
try {
|
|
165
|
-
const { result } = await
|
|
177
|
+
const { result } = await auth.getUser();
|
|
166
178
|
setUser(result.user);
|
|
167
179
|
setIsAuthenticated(true);
|
|
168
180
|
} catch {
|
|
169
181
|
setUser(null);
|
|
170
182
|
setIsAuthenticated(false);
|
|
171
|
-
|
|
183
|
+
auth.setAccessToken(void 0);
|
|
172
184
|
await clearToken();
|
|
173
185
|
} finally {
|
|
174
186
|
setIsLoading(false);
|
|
175
187
|
}
|
|
176
|
-
}, [
|
|
188
|
+
}, [auth]);
|
|
177
189
|
const logout = useCallback6(async () => {
|
|
178
190
|
try {
|
|
179
|
-
await
|
|
191
|
+
await auth.logout();
|
|
180
192
|
} catch {
|
|
181
193
|
}
|
|
182
|
-
|
|
194
|
+
auth.setAccessToken(void 0);
|
|
183
195
|
await clearToken();
|
|
184
196
|
setUser(null);
|
|
185
197
|
setIsAuthenticated(false);
|
|
186
|
-
}, [
|
|
198
|
+
}, [auth]);
|
|
187
199
|
useEffect(() => {
|
|
188
200
|
readToken().then((token) => {
|
|
189
|
-
if (token)
|
|
201
|
+
if (token) auth.setAccessToken(token);
|
|
190
202
|
void refresh();
|
|
191
203
|
});
|
|
192
|
-
}, [
|
|
204
|
+
}, [auth, refresh]);
|
|
193
205
|
return { user, isLoading, isAuthenticated, refresh, logout };
|
|
194
206
|
}
|
|
195
207
|
|
|
196
208
|
// src/hooks/useVerifyEmail.ts
|
|
197
209
|
import { FonderieApiError as FonderieApiError6 } from "@fonderie/client";
|
|
210
|
+
import { useFonderieSubClient as useFonderieSubClient7 } from "@fonderie/react";
|
|
198
211
|
import { useCallback as useCallback7, useState as useState7 } from "react";
|
|
199
212
|
function useVerifyEmail(client) {
|
|
213
|
+
const auth = useFonderieSubClient7(client, (c) => c.auth, "useVerifyEmail");
|
|
200
214
|
const [isLoading, setIsLoading] = useState7(false);
|
|
201
215
|
const [error, setError] = useState7(null);
|
|
202
216
|
const [data, setData] = useState7(null);
|
|
@@ -205,7 +219,7 @@ function useVerifyEmail(client) {
|
|
|
205
219
|
setIsLoading(true);
|
|
206
220
|
setError(null);
|
|
207
221
|
try {
|
|
208
|
-
const { result } = await
|
|
222
|
+
const { result } = await auth.verifyEmail(pin);
|
|
209
223
|
setData(result);
|
|
210
224
|
return result;
|
|
211
225
|
} catch (err) {
|
|
@@ -216,7 +230,7 @@ function useVerifyEmail(client) {
|
|
|
216
230
|
setIsLoading(false);
|
|
217
231
|
}
|
|
218
232
|
},
|
|
219
|
-
[
|
|
233
|
+
[auth]
|
|
220
234
|
);
|
|
221
235
|
return { verifyEmail, isLoading, error, data };
|
|
222
236
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/useForgotPassword.ts","../src/hooks/useLogin.ts","../src/storage.ts","../src/hooks/useLogout.ts","../src/hooks/useRegister.ts","../src/hooks/useResetPassword.ts","../src/hooks/useSession.ts","../src/hooks/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseForgotPasswordReturn,\n\tIUseLoginReturn,\n\tIUseLogoutReturn,\n\tIUseRegisterReturn,\n\tIUseResetPasswordReturn,\n\tIUseSessionReturn,\n\tIUseVerifyEmailReturn,\n} from './hooks';\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './hooks';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseForgotPasswordReturn {\n\tforgotPassword: (email: string) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tsent: boolean;\n}\n\nexport function useForgotPassword(client: AuthClient): IUseForgotPasswordReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [sent, setSent] = useState(false);\n\n\tconst forgotPassword = useCallback(\n\t\tasync (email: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.forgotPassword(email);\n\t\t\t\tsetSent(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseLoginReturn {\n\tlogin: (input: ILoginInput) => Promise<ILoginResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: ILoginResult | null;\n}\n\nexport function useLogin(client: AuthClient): IUseLoginReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<ILoginResult | null>(null);\n\n\tconst login = useCallback(\n\t\tasync (input: ILoginInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.login(input);\n\t\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { login, isLoading, error, data };\n}\n","import AsyncStorage from '@react-native-async-storage/async-storage';\n\nexport const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\treturn AsyncStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\treturn AsyncStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken() {\n\treturn AsyncStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\nimport { clearToken } from '../storage';\n\nexport interface IUseLogoutReturn {\n\tlogout: () => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useLogout(client: AuthClient): IUseLogoutReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst logout = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseRegisterReturn {\n\tregister: (input: IRegisterInput) => Promise<IRegisterResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IRegisterResult | null;\n}\n\nexport function useRegister(client: AuthClient): IUseRegisterReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IRegisterResult | null>(null);\n\n\tconst register = useCallback(\n\t\tasync (input: IRegisterInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.register(input);\n\t\t\t\tclient.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseResetPasswordReturn {\n\tresetPassword: (input: IResetPasswordInput) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdone: boolean;\n}\n\nexport function useResetPassword(client: AuthClient): IUseResetPasswordReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [done, setDone] = useState(false);\n\n\tconst resetPassword = useCallback(\n\t\tasync (input: IResetPasswordInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait client.resetPassword(input);\n\t\t\t\tsetDone(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { clearToken, readToken } from '../storage';\n\nexport interface IUseSessionReturn {\n\tuser: IUserDTO | null;\n\tisLoading: boolean;\n\tisAuthenticated: boolean;\n\trefresh: () => Promise<void>;\n\tlogout: () => Promise<void>;\n}\n\nexport function useSession(client: AuthClient): IUseSessionReturn {\n\tconst [user, setUser] = useState<IUserDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [isAuthenticated, setIsAuthenticated] = useState(false);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\ttry {\n\t\t\tconst { result } = await client.getUser();\n\t\t\tsetUser(result.user);\n\t\t\tsetIsAuthenticated(true);\n\t\t} catch {\n\t\t\tsetUser(null);\n\t\t\tsetIsAuthenticated(false);\n\t\t\tclient.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [client]);\n\n\tconst logout = useCallback(async () => {\n\t\ttry {\n\t\t\tawait client.logout();\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tclient.setAccessToken(undefined);\n\t\tawait clearToken();\n\t\tsetUser(null);\n\t\tsetIsAuthenticated(false);\n\t}, [client]);\n\n\tuseEffect(() => {\n\t\treadToken().then((token) => {\n\t\t\tif (token) client.setAccessToken(token);\n\t\t\tvoid refresh();\n\t\t});\n\t}, [client, refresh]);\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseVerifyEmailReturn {\n\tverifyEmail: (pin: string) => Promise<IVerifyEmailResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IVerifyEmailResult | null;\n}\n\nexport function useVerifyEmail(client: AuthClient): IUseVerifyEmailReturn {\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IVerifyEmailResult | null>(null);\n\n\tconst verifyEmail = useCallback(\n\t\tasync (pin: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await client.verifyEmail(pin);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[client],\n\t);\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";AAYA,SAAS,oBAAAA,yBAAwB;;;ACXjC,SAAS,wBAAwB;AACjC,SAAS,aAAa,gBAAgB;AAS/B,SAAS,kBAAkB,QAA8C;AAC/E,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkC,IAAI;AAChE,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AAEtC,QAAM,iBAAiB;AAAA,IACtB,OAAO,UAAkB;AACxB,m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oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,MAAM;AAAA,EACR;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["FonderieApiError","FonderieApiError","useCallback","useState","useState","useCallback","FonderieApiError","FonderieApiError","useCallback","useState","useState","useCallback","FonderieApiError","FonderieApiError","useCallback","useState","useState","useCallback","FonderieApiError","FonderieApiError","useCallback","useState","useCallback","useState","useState","useCallback","FonderieApiError","useCallback","useState"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/useForgotPassword.ts","../src/hooks/useLogin.ts","../src/storage.ts","../src/hooks/useLogout.ts","../src/hooks/useRegister.ts","../src/hooks/useResetPassword.ts","../src/hooks/useSession.ts","../src/hooks/useVerifyEmail.ts"],"sourcesContent":["export type {\n\tAuthClient,\n\tILoginInput,\n\tILoginResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError } from '@fonderie/client';\nexport type {\n\tIUseForgotPasswordReturn,\n\tIUseLoginReturn,\n\tIUseLogoutReturn,\n\tIUseRegisterReturn,\n\tIUseResetPasswordReturn,\n\tIUseSessionReturn,\n\tIUseVerifyEmailReturn,\n} from './hooks';\nexport {\n\tuseForgotPassword,\n\tuseLogin,\n\tuseLogout,\n\tuseRegister,\n\tuseResetPassword,\n\tuseSession,\n\tuseVerifyEmail,\n} from './hooks';\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseForgotPasswordReturn {\n\tforgotPassword: (email: string) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tsent: boolean;\n}\n\nexport function useForgotPassword(client?: AuthClient): IUseForgotPasswordReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useForgotPassword');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [sent, setSent] = useState(false);\n\n\tconst forgotPassword = useCallback(\n\t\tasync (email: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait auth.forgotPassword(email);\n\t\t\t\tsetSent(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { forgotPassword, isLoading, error, sent };\n}\n","import type { AuthClient, ILoginInput, ILoginResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseLoginReturn {\n\tlogin: (input: ILoginInput) => Promise<ILoginResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: ILoginResult | null;\n}\n\nexport function useLogin(client?: AuthClient): IUseLoginReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogin');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<ILoginResult | null>(null);\n\n\tconst login = useCallback(\n\t\tasync (input: ILoginInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.login(input);\n\t\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { login, isLoading, error, data };\n}\n","import AsyncStorage from '@react-native-async-storage/async-storage';\n\nexport const TOKEN_KEY = 'fonderie_access_token';\n\nexport function persistToken(token: string) {\n\treturn AsyncStorage.setItem(TOKEN_KEY, token);\n}\n\nexport function clearToken() {\n\treturn AsyncStorage.removeItem(TOKEN_KEY);\n}\n\nexport function readToken() {\n\treturn AsyncStorage.getItem(TOKEN_KEY);\n}\n","import type { AuthClient } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\nimport { clearToken } from '../storage';\n\nexport interface IUseLogoutReturn {\n\tlogout: () => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n}\n\nexport function useLogout(client?: AuthClient): IUseLogoutReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useLogout');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\n\tconst logout = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tawait auth.logout();\n\t\t} catch (err) {\n\t\t\tconst apiError =\n\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\tsetError(apiError);\n\t\t} finally {\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [auth]);\n\n\treturn { logout, isLoading, error };\n}\n","import type { AuthClient, IRegisterInput, IRegisterResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\nimport { persistToken } from '../storage';\n\nexport interface IUseRegisterReturn {\n\tregister: (input: IRegisterInput) => Promise<IRegisterResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IRegisterResult | null;\n}\n\nexport function useRegister(client?: AuthClient): IUseRegisterReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useRegister');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IRegisterResult | null>(null);\n\n\tconst register = useCallback(\n\t\tasync (input: IRegisterInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.register(input);\n\t\t\t\tauth.setAccessToken(result.tokens.access);\n\t\t\t\tawait persistToken(result.tokens.access);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { register, isLoading, error, data };\n}\n","import type { AuthClient, IResetPasswordInput } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseResetPasswordReturn {\n\tresetPassword: (input: IResetPasswordInput) => Promise<void>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdone: boolean;\n}\n\nexport function useResetPassword(client?: AuthClient): IUseResetPasswordReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useResetPassword');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [done, setDone] = useState(false);\n\n\tconst resetPassword = useCallback(\n\t\tasync (input: IResetPasswordInput) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tawait auth.resetPassword(input);\n\t\t\t\tsetDone(true);\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { resetPassword, isLoading, error, done };\n}\n","import type { AuthClient, IUserDTO } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useEffect, useState } from 'react';\nimport { clearToken, readToken } from '../storage';\n\nexport interface IUseSessionReturn {\n\tuser: IUserDTO | null;\n\tisLoading: boolean;\n\tisAuthenticated: boolean;\n\trefresh: () => Promise<void>;\n\tlogout: () => Promise<void>;\n}\n\nexport function useSession(client?: AuthClient): IUseSessionReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useSession');\n\tconst [user, setUser] = useState<IUserDTO | null>(null);\n\tconst [isLoading, setIsLoading] = useState(true);\n\tconst [isAuthenticated, setIsAuthenticated] = useState(false);\n\n\tconst refresh = useCallback(async () => {\n\t\tsetIsLoading(true);\n\t\ttry {\n\t\t\tconst { result } = await auth.getUser();\n\t\t\tsetUser(result.user);\n\t\t\tsetIsAuthenticated(true);\n\t\t} catch {\n\t\t\tsetUser(null);\n\t\t\tsetIsAuthenticated(false);\n\t\t\tauth.setAccessToken(undefined);\n\t\t\tawait clearToken();\n\t\t} finally {\n\t\t\tsetIsLoading(false);\n\t\t}\n\t}, [auth]);\n\n\tconst logout = useCallback(async () => {\n\t\ttry {\n\t\t\tawait auth.logout();\n\t\t} catch {\n\t\t\t// Session is being torn down regardless of server response.\n\t\t}\n\t\tauth.setAccessToken(undefined);\n\t\tawait clearToken();\n\t\tsetUser(null);\n\t\tsetIsAuthenticated(false);\n\t}, [auth]);\n\n\tuseEffect(() => {\n\t\treadToken().then((token) => {\n\t\t\tif (token) auth.setAccessToken(token);\n\t\t\tvoid refresh();\n\t\t});\n\t}, [auth, refresh]);\n\n\treturn { user, isLoading, isAuthenticated, refresh, logout };\n}\n","import type { AuthClient, IVerifyEmailResult } from '@fonderie/client';\nimport { FonderieApiError } from '@fonderie/client';\nimport { useFonderieSubClient } from '@fonderie/react';\nimport { useCallback, useState } from 'react';\n\nexport interface IUseVerifyEmailReturn {\n\tverifyEmail: (pin: string) => Promise<IVerifyEmailResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: IVerifyEmailResult | null;\n}\n\nexport function useVerifyEmail(client?: AuthClient): IUseVerifyEmailReturn {\n\tconst auth = useFonderieSubClient(client, (c) => c.auth, 'useVerifyEmail');\n\tconst [isLoading, setIsLoading] = useState(false);\n\tconst [error, setError] = useState<FonderieApiError | null>(null);\n\tconst [data, setData] = useState<IVerifyEmailResult | null>(null);\n\n\tconst verifyEmail = useCallback(\n\t\tasync (pin: string) => {\n\t\t\tsetIsLoading(true);\n\t\t\tsetError(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.verifyEmail(pin);\n\t\t\t\tsetData(result);\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tconst apiError =\n\t\t\t\t\terr instanceof FonderieApiError ? err : new FonderieApiError('unknown', String(err), 0);\n\t\t\t\tsetError(apiError);\n\t\t\t\tthrow apiError;\n\t\t\t} finally {\n\t\t\t\tsetIsLoading(false);\n\t\t\t}\n\t\t},\n\t\t[auth],\n\t);\n\n\treturn { verifyEmail, isLoading, error, data };\n}\n"],"mappings":";AAYA,SAAS,oBAAAA,yBAAwB;;;ACXjC,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,aAAa,gBAAgB;A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AI;AACZ,uBAAmB,KAAK;AAAA,EACzB,GAAG,CAAC,IAAI,CAAC;AAET,YAAU,MAAM;AACf,cAAU,EAAE,KAAK,CAAC,UAAU;AAC3B,UAAI,MAAO,MAAK,eAAe,KAAK;AACpC,WAAK,QAAQ;AAAA,IACd,CAAC;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,SAAO,EAAE,MAAM,WAAW,iBAAiB,SAAS,OAAO;AAC5D;;;ACtDA,SAAS,oBAAAC,yBAAwB;AACjC,SAAS,wBAAAC,6BAA4B;AACrC,SAAS,eAAAC,cAAa,YAAAC,iBAAgB;AAS/B,SAAS,eAAe,QAA4C;AAC1E,QAAM,OAAOF,sBAAqB,QAAQ,CAAC,MAAM,EAAE,MAAM,gBAAgB;AACzE,QAAM,CAAC,WAAW,YAAY,IAAIE,UAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAkC,IAAI;AAChE,QAAM,CAAC,MAAM,OAAO,IAAIA,UAAoC,IAAI;AAEhE,QAAM,cAAcD;AAAA,IACnB,OAAO,QAAgB;AACtB,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,EAAE,OAAO,IAAI,MAAM,KAAK,YAAY,GAAG;AAC7C,gBAAQ,MAAM;AACd,eAAO;AAAA,MACR,SAAS,KAAK;AACb,cAAM,WACL,eAAeF,oBAAmB,MAAM,IAAIA,kBAAiB,WAAW,OAAO,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAAC,IAAI;AAAA,EACN;AAEA,SAAO,EAAE,aAAa,WAAW,OAAO,KAAK;AAC9C;","names":["FonderieApiError","FonderieApiError","useFonderieSubClient","useCallback","useState","useFonderieSubClient","useState","useCallback","FonderieApiError","FonderieApiError","useFonderieSubClient","useCallback","useState","useFonderieSubClient","useState","useCallback","FonderieApiError","FonderieApiError","useFonderieSubClient","useCallback","useState","useFonderieSubClient","useState","useCallback","FonderieApiError","FonderieApiError","useFonderieSubClient","useCallback","useState","useFonderieSubClient","useCallback","useState","useFonderieSubClient","useState","useCallback","FonderieApiError","useFonderieSubClient","useCallback","useState"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonderie/react-native-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React Native hooks for Fonderie auth — thin bindings over @fonderie/client.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"fonderiejs",
|
|
7
7
|
"react-native",
|
|
8
8
|
"auth",
|
|
9
9
|
"hooks",
|
|
@@ -28,25 +28,28 @@
|
|
|
28
28
|
"build": "tsup",
|
|
29
29
|
"dev": "tsup --watch",
|
|
30
30
|
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "tsx --tsconfig tsconfig.test.json --test src/__tests__/*.test.tsx",
|
|
31
32
|
"lint": "biome lint src",
|
|
32
33
|
"format": "biome format --write src",
|
|
33
34
|
"check": "biome check --write src"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@fonderie/client": "*"
|
|
37
|
+
"@fonderie/client": "*",
|
|
38
|
+
"@fonderie/react": "*"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"react": ">=18.0.0",
|
|
40
42
|
"@react-native-async-storage/async-storage": ">=1.18.0"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@react-native-async-storage/async-storage": "1.
|
|
44
|
-
"@types/
|
|
45
|
-
"react
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"react": "
|
|
45
|
+
"@react-native-async-storage/async-storage": "3.1.1",
|
|
46
|
+
"@types/node": "^26.2.0",
|
|
47
|
+
"@types/react": "^19.2.18",
|
|
48
|
+
"react": "^19.2.8",
|
|
49
|
+
"react-dom": "^19.2.8",
|
|
50
|
+
"react-native": "0.87.0",
|
|
49
51
|
"tsup": "^8.5.1",
|
|
52
|
+
"tsx": "^4.21.0",
|
|
50
53
|
"typescript": "^6.0.3"
|
|
51
54
|
},
|
|
52
55
|
"publishConfig": {
|