@fonderie/react-native-auth 0.2.0 → 0.4.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/dist/index.cjs +13 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
FonderieApiError: () => import_client7.FonderieApiError,
|
|
34
|
+
isMfaRequired: () => import_client7.isMfaRequired,
|
|
34
35
|
useForgotPassword: () => useForgotPassword,
|
|
35
36
|
useLogin: () => useLogin,
|
|
36
37
|
useLogout: () => useLogout,
|
|
@@ -95,12 +96,18 @@ function useLogin(client) {
|
|
|
95
96
|
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
96
97
|
const [error, setError] = (0, import_react4.useState)(null);
|
|
97
98
|
const [data, setData] = (0, import_react4.useState)(null);
|
|
99
|
+
const [mfaPending, setMfaPending] = (0, import_react4.useState)(null);
|
|
98
100
|
const login = (0, import_react4.useCallback)(
|
|
99
101
|
async (input) => {
|
|
100
102
|
setIsLoading(true);
|
|
101
103
|
setError(null);
|
|
104
|
+
setMfaPending(null);
|
|
102
105
|
try {
|
|
103
106
|
const { result } = await auth.login(input);
|
|
107
|
+
if ((0, import_client2.isMfaRequired)(result)) {
|
|
108
|
+
setMfaPending(result);
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
104
111
|
auth.setAccessToken(result.tokens.access);
|
|
105
112
|
await persistToken(result.tokens.access);
|
|
106
113
|
setData(result);
|
|
@@ -115,7 +122,7 @@ function useLogin(client) {
|
|
|
115
122
|
},
|
|
116
123
|
[auth]
|
|
117
124
|
);
|
|
118
|
-
return { login, isLoading, error, data };
|
|
125
|
+
return { login, isLoading, error, data, mfaPending };
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
// src/hooks/useLogout.ts
|
|
@@ -126,11 +133,11 @@ function useLogout(client) {
|
|
|
126
133
|
const auth = (0, import_react5.useFonderieSubClient)(client, (c) => c.auth, "useLogout");
|
|
127
134
|
const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
|
|
128
135
|
const [error, setError] = (0, import_react6.useState)(null);
|
|
129
|
-
const logout = (0, import_react6.useCallback)(async () => {
|
|
136
|
+
const logout = (0, import_react6.useCallback)(async (refreshToken) => {
|
|
130
137
|
setIsLoading(true);
|
|
131
138
|
setError(null);
|
|
132
139
|
try {
|
|
133
|
-
await auth.logout();
|
|
140
|
+
await auth.logout(refreshToken);
|
|
134
141
|
} catch (err) {
|
|
135
142
|
const apiError = err instanceof import_client3.FonderieApiError ? err : new import_client3.FonderieApiError("unknown", String(err), 0);
|
|
136
143
|
setError(apiError);
|
|
@@ -227,9 +234,9 @@ function useSession(client) {
|
|
|
227
234
|
setIsLoading(false);
|
|
228
235
|
}
|
|
229
236
|
}, [auth]);
|
|
230
|
-
const logout = (0, import_react12.useCallback)(async () => {
|
|
237
|
+
const logout = (0, import_react12.useCallback)(async (refreshToken) => {
|
|
231
238
|
try {
|
|
232
|
-
await auth.logout();
|
|
239
|
+
await auth.logout(refreshToken);
|
|
233
240
|
} catch {
|
|
234
241
|
}
|
|
235
242
|
auth.setAccessToken(void 0);
|
|
@@ -278,6 +285,7 @@ function useVerifyEmail(client) {
|
|
|
278
285
|
// Annotate the CommonJS export names for ESM import in node:
|
|
279
286
|
0 && (module.exports = {
|
|
280
287
|
FonderieApiError,
|
|
288
|
+
isMfaRequired,
|
|
281
289
|
useForgotPassword,
|
|
282
290
|
useLogin,
|
|
283
291
|
useLogout,
|
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 { 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,M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M,CAAC,MAAM,OAAO,QAAI,yBAAoC,IAAI;AAEhE,QAAM,kBAAc;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,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"]}
|
|
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\tIMfaRequiredResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError, isMfaRequired } 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, IMfaRequiredResult } from '@fonderie/client';\nimport { FonderieApiError, isMfaRequired } 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 | IMfaRequiredResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: ILoginResult | null;\n\t// Set when the account requires MFA: no tokens were issued — complete the\n\t// login with client.auth.mfa.verifyLogin(mfaPending.mfaToken, code).\n\tmfaPending: IMfaRequiredResult | 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\tconst [mfaPending, setMfaPending] = useState<IMfaRequiredResult | 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\tsetMfaPending(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.login(input);\n\t\t\t\tif (isMfaRequired(result)) {\n\t\t\t\t\tsetMfaPending(result);\n\t\t\t\t\treturn result;\n\t\t\t\t}\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, mfaPending };\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: (refreshToken?: string) => 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 (refreshToken?: string) => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\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: (refreshToken?: string) => 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 (refreshToken?: string) => {\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\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;AAAA;AAaA,IAAAA,iBAAgD;;;ACZhD,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,GAAG,GAAG,CAAC;AACvF,iBAAS,QAAQ;AACjB,cAAM;AAAA,MACP,UAAE;AACD,qBAAa,KAAK;AAAA,MACnB;AAAA,IACD;AAAA,IACA,CAA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AAO,QAAI,yBAAoC,IAAI;AAEhE,QAAM,kBAAc;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,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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FonderieApiError, AuthClient, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
2
|
-
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
1
|
+
import { FonderieApiError, AuthClient, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
2
|
+
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult, isMfaRequired } from '@fonderie/client';
|
|
3
3
|
|
|
4
4
|
interface IUseForgotPasswordReturn {
|
|
5
5
|
forgotPassword: (email: string) => Promise<void>;
|
|
@@ -10,15 +10,16 @@ interface IUseForgotPasswordReturn {
|
|
|
10
10
|
declare function useForgotPassword(client?: AuthClient): IUseForgotPasswordReturn;
|
|
11
11
|
|
|
12
12
|
interface IUseLoginReturn {
|
|
13
|
-
login: (input: ILoginInput) => Promise<ILoginResult>;
|
|
13
|
+
login: (input: ILoginInput) => Promise<ILoginResult | IMfaRequiredResult>;
|
|
14
14
|
isLoading: boolean;
|
|
15
15
|
error: FonderieApiError | null;
|
|
16
16
|
data: ILoginResult | null;
|
|
17
|
+
mfaPending: IMfaRequiredResult | null;
|
|
17
18
|
}
|
|
18
19
|
declare function useLogin(client?: AuthClient): IUseLoginReturn;
|
|
19
20
|
|
|
20
21
|
interface IUseLogoutReturn {
|
|
21
|
-
logout: () => Promise<void>;
|
|
22
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
22
23
|
isLoading: boolean;
|
|
23
24
|
error: FonderieApiError | null;
|
|
24
25
|
}
|
|
@@ -45,7 +46,7 @@ interface IUseSessionReturn {
|
|
|
45
46
|
isLoading: boolean;
|
|
46
47
|
isAuthenticated: boolean;
|
|
47
48
|
refresh: () => Promise<void>;
|
|
48
|
-
logout: () => Promise<void>;
|
|
49
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
49
50
|
}
|
|
50
51
|
declare function useSession(client?: AuthClient): IUseSessionReturn;
|
|
51
52
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FonderieApiError, AuthClient, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
2
|
-
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
1
|
+
import { FonderieApiError, AuthClient, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, IUserDTO, IVerifyEmailResult } from '@fonderie/client';
|
|
2
|
+
export { AuthClient, FonderieApiError, ILoginInput, ILoginResult, IMfaRequiredResult, IRegisterInput, IRegisterResult, IResetPasswordInput, ITokens, IUserDTO, IVerifyEmailResult, isMfaRequired } from '@fonderie/client';
|
|
3
3
|
|
|
4
4
|
interface IUseForgotPasswordReturn {
|
|
5
5
|
forgotPassword: (email: string) => Promise<void>;
|
|
@@ -10,15 +10,16 @@ interface IUseForgotPasswordReturn {
|
|
|
10
10
|
declare function useForgotPassword(client?: AuthClient): IUseForgotPasswordReturn;
|
|
11
11
|
|
|
12
12
|
interface IUseLoginReturn {
|
|
13
|
-
login: (input: ILoginInput) => Promise<ILoginResult>;
|
|
13
|
+
login: (input: ILoginInput) => Promise<ILoginResult | IMfaRequiredResult>;
|
|
14
14
|
isLoading: boolean;
|
|
15
15
|
error: FonderieApiError | null;
|
|
16
16
|
data: ILoginResult | null;
|
|
17
|
+
mfaPending: IMfaRequiredResult | null;
|
|
17
18
|
}
|
|
18
19
|
declare function useLogin(client?: AuthClient): IUseLoginReturn;
|
|
19
20
|
|
|
20
21
|
interface IUseLogoutReturn {
|
|
21
|
-
logout: () => Promise<void>;
|
|
22
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
22
23
|
isLoading: boolean;
|
|
23
24
|
error: FonderieApiError | null;
|
|
24
25
|
}
|
|
@@ -45,7 +46,7 @@ interface IUseSessionReturn {
|
|
|
45
46
|
isLoading: boolean;
|
|
46
47
|
isAuthenticated: boolean;
|
|
47
48
|
refresh: () => Promise<void>;
|
|
48
|
-
logout: () => Promise<void>;
|
|
49
|
+
logout: (refreshToken?: string) => Promise<void>;
|
|
49
50
|
}
|
|
50
51
|
declare function useSession(client?: AuthClient): IUseSessionReturn;
|
|
51
52
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { FonderieApiError as FonderieApiError7 } from "@fonderie/client";
|
|
2
|
+
import { FonderieApiError as FonderieApiError7, isMfaRequired as isMfaRequired2 } from "@fonderie/client";
|
|
3
3
|
|
|
4
4
|
// src/hooks/useForgotPassword.ts
|
|
5
5
|
import { FonderieApiError } from "@fonderie/client";
|
|
@@ -31,7 +31,7 @@ function useForgotPassword(client) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// src/hooks/useLogin.ts
|
|
34
|
-
import { FonderieApiError as FonderieApiError2 } from "@fonderie/client";
|
|
34
|
+
import { FonderieApiError as FonderieApiError2, isMfaRequired } from "@fonderie/client";
|
|
35
35
|
import { useFonderieSubClient as useFonderieSubClient2 } from "@fonderie/react";
|
|
36
36
|
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
37
37
|
|
|
@@ -54,12 +54,18 @@ function useLogin(client) {
|
|
|
54
54
|
const [isLoading, setIsLoading] = useState2(false);
|
|
55
55
|
const [error, setError] = useState2(null);
|
|
56
56
|
const [data, setData] = useState2(null);
|
|
57
|
+
const [mfaPending, setMfaPending] = useState2(null);
|
|
57
58
|
const login = useCallback2(
|
|
58
59
|
async (input) => {
|
|
59
60
|
setIsLoading(true);
|
|
60
61
|
setError(null);
|
|
62
|
+
setMfaPending(null);
|
|
61
63
|
try {
|
|
62
64
|
const { result } = await auth.login(input);
|
|
65
|
+
if (isMfaRequired(result)) {
|
|
66
|
+
setMfaPending(result);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
63
69
|
auth.setAccessToken(result.tokens.access);
|
|
64
70
|
await persistToken(result.tokens.access);
|
|
65
71
|
setData(result);
|
|
@@ -74,7 +80,7 @@ function useLogin(client) {
|
|
|
74
80
|
},
|
|
75
81
|
[auth]
|
|
76
82
|
);
|
|
77
|
-
return { login, isLoading, error, data };
|
|
83
|
+
return { login, isLoading, error, data, mfaPending };
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
// src/hooks/useLogout.ts
|
|
@@ -85,11 +91,11 @@ function useLogout(client) {
|
|
|
85
91
|
const auth = useFonderieSubClient3(client, (c) => c.auth, "useLogout");
|
|
86
92
|
const [isLoading, setIsLoading] = useState3(false);
|
|
87
93
|
const [error, setError] = useState3(null);
|
|
88
|
-
const logout = useCallback3(async () => {
|
|
94
|
+
const logout = useCallback3(async (refreshToken) => {
|
|
89
95
|
setIsLoading(true);
|
|
90
96
|
setError(null);
|
|
91
97
|
try {
|
|
92
|
-
await auth.logout();
|
|
98
|
+
await auth.logout(refreshToken);
|
|
93
99
|
} catch (err) {
|
|
94
100
|
const apiError = err instanceof FonderieApiError3 ? err : new FonderieApiError3("unknown", String(err), 0);
|
|
95
101
|
setError(apiError);
|
|
@@ -186,9 +192,9 @@ function useSession(client) {
|
|
|
186
192
|
setIsLoading(false);
|
|
187
193
|
}
|
|
188
194
|
}, [auth]);
|
|
189
|
-
const logout = useCallback6(async () => {
|
|
195
|
+
const logout = useCallback6(async (refreshToken) => {
|
|
190
196
|
try {
|
|
191
|
-
await auth.logout();
|
|
197
|
+
await auth.logout(refreshToken);
|
|
192
198
|
} catch {
|
|
193
199
|
}
|
|
194
200
|
auth.setAccessToken(void 0);
|
|
@@ -236,6 +242,7 @@ function useVerifyEmail(client) {
|
|
|
236
242
|
}
|
|
237
243
|
export {
|
|
238
244
|
FonderieApiError7 as FonderieApiError,
|
|
245
|
+
isMfaRequired2 as isMfaRequired,
|
|
239
246
|
useForgotPassword,
|
|
240
247
|
useLogin,
|
|
241
248
|
useLogout,
|
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 { 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;AAS/B,SAAS,kBAAkB,QAA+C;AAChF,QAAM,OAAO,qBAAqB,QAAQ,CAAC,MAAM,EAAE,MAAM,mBAAmB;AAC5E,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,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,KAAK,eAAe,KAAK;AAC/B,gBAAQ,IAAI;AAAA,MACb,SAAS,KAAK;AACb,cAAM,WACL,eAAe,mBAAmB,MAAM,IAAI,iBAAiB,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,gBAAgB,WAAW,OAAO,KAAK;AACjD;;;ACrCA,SAAS,oBAAAC,yBAAwB;AACjC,SAAS,wBAAAC,6BAA4B;AACrC,SAAS,eAAAC,cAAa,YAAAC,iBAAgB;;;ACHtC,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G;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"]}
|
|
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\tIMfaRequiredResult,\n\tIRegisterInput,\n\tIRegisterResult,\n\tIResetPasswordInput,\n\tITokens,\n\tIUserDTO,\n\tIVerifyEmailResult,\n} from '@fonderie/client';\n\nexport { FonderieApiError, isMfaRequired } 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, IMfaRequiredResult } from '@fonderie/client';\nimport { FonderieApiError, isMfaRequired } 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 | IMfaRequiredResult>;\n\tisLoading: boolean;\n\terror: FonderieApiError | null;\n\tdata: ILoginResult | null;\n\t// Set when the account requires MFA: no tokens were issued — complete the\n\t// login with client.auth.mfa.verifyLogin(mfaPending.mfaToken, code).\n\tmfaPending: IMfaRequiredResult | 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\tconst [mfaPending, setMfaPending] = useState<IMfaRequiredResult | 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\tsetMfaPending(null);\n\t\t\ttry {\n\t\t\t\tconst { result } = await auth.login(input);\n\t\t\t\tif (isMfaRequired(result)) {\n\t\t\t\t\tsetMfaPending(result);\n\t\t\t\t\treturn result;\n\t\t\t\t}\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, mfaPending };\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: (refreshToken?: string) => 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 (refreshToken?: string) => {\n\t\tsetIsLoading(true);\n\t\tsetError(null);\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\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: (refreshToken?: string) => 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 (refreshToken?: string) => {\n\t\ttry {\n\t\t\tawait auth.logout(refreshToken);\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,SAAS,oBAAAA,mBAAkB,iBAAAC,sBAAqB;;;ACZhD,SAAS,wBAAwB;AACjC,SAAS,4BAA4B;AACrC,SAAS,aAAa,gBAAgB;AAS/B,SAAS,kBAAkB,QAA+C;AAChF,QAAM,OAAO,qBAAqB,QAAQ,CAAC,MAAM,EAAE,MAAM,mBAAmB;AAC5E,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,mBAAa,IAAI;AACjB,eAAS,IAAI;AACb,UAAI;AACH,cAAM,KAAK,eAAe,KAAK;AAC/B,gBAAQ,IAAI;AAAA,MACb,SAAS,KAAK;AACb,cAAM,WACL,eAAe,mBAAmB,MAAM,IAAI,iBAAiB,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,SA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,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","isMfaRequired","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"]}
|