@redmix/auth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +148 -0
- package/dist/AuthContext.d.ts +69 -0
- package/dist/AuthContext.d.ts.map +1 -0
- package/dist/AuthContext.js +7 -0
- package/dist/AuthImplementation.d.ts +49 -0
- package/dist/AuthImplementation.d.ts.map +1 -0
- package/dist/AuthImplementation.js +0 -0
- package/dist/AuthProvider/AuthProvider.d.ts +12 -0
- package/dist/AuthProvider/AuthProvider.d.ts.map +1 -0
- package/dist/AuthProvider/AuthProvider.js +83 -0
- package/dist/AuthProvider/AuthProviderState.d.ts +13 -0
- package/dist/AuthProvider/AuthProviderState.d.ts.map +1 -0
- package/dist/AuthProvider/AuthProviderState.js +18 -0
- package/dist/AuthProvider/ServerAuthProvider.d.ts +23 -0
- package/dist/AuthProvider/ServerAuthProvider.d.ts.map +1 -0
- package/dist/AuthProvider/ServerAuthProvider.js +43 -0
- package/dist/AuthProvider/useCurrentUser.d.ts +3 -0
- package/dist/AuthProvider/useCurrentUser.d.ts.map +1 -0
- package/dist/AuthProvider/useCurrentUser.js +31 -0
- package/dist/AuthProvider/useForgotPassword.d.ts +3 -0
- package/dist/AuthProvider/useForgotPassword.d.ts.map +1 -0
- package/dist/AuthProvider/useForgotPassword.js +18 -0
- package/dist/AuthProvider/useHasRole.d.ts +3 -0
- package/dist/AuthProvider/useHasRole.d.ts.map +1 -0
- package/dist/AuthProvider/useHasRole.js +34 -0
- package/dist/AuthProvider/useLogIn.d.ts +5 -0
- package/dist/AuthProvider/useLogIn.d.ts.map +1 -0
- package/dist/AuthProvider/useLogIn.js +22 -0
- package/dist/AuthProvider/useLogOut.d.ts +4 -0
- package/dist/AuthProvider/useLogOut.d.ts.map +1 -0
- package/dist/AuthProvider/useLogOut.js +21 -0
- package/dist/AuthProvider/useReauthenticate.d.ts +5 -0
- package/dist/AuthProvider/useReauthenticate.d.ts.map +1 -0
- package/dist/AuthProvider/useReauthenticate.js +57 -0
- package/dist/AuthProvider/useResetPassword.d.ts +3 -0
- package/dist/AuthProvider/useResetPassword.d.ts.map +1 -0
- package/dist/AuthProvider/useResetPassword.js +18 -0
- package/dist/AuthProvider/useSignUp.d.ts +5 -0
- package/dist/AuthProvider/useSignUp.d.ts.map +1 -0
- package/dist/AuthProvider/useSignUp.js +20 -0
- package/dist/AuthProvider/useToken.d.ts +3 -0
- package/dist/AuthProvider/useToken.d.ts.map +1 -0
- package/dist/AuthProvider/useToken.js +15 -0
- package/dist/AuthProvider/useValidateResetToken.d.ts +3 -0
- package/dist/AuthProvider/useValidateResetToken.d.ts.map +1 -0
- package/dist/AuthProvider/useValidateResetToken.js +18 -0
- package/dist/authFactory.d.ts +15 -0
- package/dist/authFactory.d.ts.map +1 -0
- package/dist/authFactory.js +16 -0
- package/dist/cjs/AuthContext.d.ts +69 -0
- package/dist/cjs/AuthContext.d.ts.map +1 -0
- package/dist/cjs/AuthContext.js +41 -0
- package/dist/cjs/AuthImplementation.d.ts +49 -0
- package/dist/cjs/AuthImplementation.d.ts.map +1 -0
- package/dist/cjs/AuthImplementation.js +16 -0
- package/dist/cjs/AuthProvider/AuthProvider.d.ts +12 -0
- package/dist/cjs/AuthProvider/AuthProvider.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/AuthProvider.js +117 -0
- package/dist/cjs/AuthProvider/AuthProviderState.d.ts +13 -0
- package/dist/cjs/AuthProvider/AuthProviderState.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/AuthProviderState.js +43 -0
- package/dist/cjs/AuthProvider/ServerAuthProvider.d.ts +23 -0
- package/dist/cjs/AuthProvider/ServerAuthProvider.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/ServerAuthProvider.js +78 -0
- package/dist/cjs/AuthProvider/useCurrentUser.d.ts +3 -0
- package/dist/cjs/AuthProvider/useCurrentUser.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useCurrentUser.js +55 -0
- package/dist/cjs/AuthProvider/useForgotPassword.d.ts +3 -0
- package/dist/cjs/AuthProvider/useForgotPassword.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useForgotPassword.js +42 -0
- package/dist/cjs/AuthProvider/useHasRole.d.ts +3 -0
- package/dist/cjs/AuthProvider/useHasRole.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useHasRole.js +58 -0
- package/dist/cjs/AuthProvider/useLogIn.d.ts +5 -0
- package/dist/cjs/AuthProvider/useLogIn.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useLogIn.js +46 -0
- package/dist/cjs/AuthProvider/useLogOut.d.ts +4 -0
- package/dist/cjs/AuthProvider/useLogOut.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useLogOut.js +45 -0
- package/dist/cjs/AuthProvider/useReauthenticate.d.ts +5 -0
- package/dist/cjs/AuthProvider/useReauthenticate.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useReauthenticate.js +81 -0
- package/dist/cjs/AuthProvider/useResetPassword.d.ts +3 -0
- package/dist/cjs/AuthProvider/useResetPassword.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useResetPassword.js +42 -0
- package/dist/cjs/AuthProvider/useSignUp.d.ts +5 -0
- package/dist/cjs/AuthProvider/useSignUp.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useSignUp.js +44 -0
- package/dist/cjs/AuthProvider/useToken.d.ts +3 -0
- package/dist/cjs/AuthProvider/useToken.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useToken.js +39 -0
- package/dist/cjs/AuthProvider/useValidateResetToken.d.ts +3 -0
- package/dist/cjs/AuthProvider/useValidateResetToken.d.ts.map +1 -0
- package/dist/cjs/AuthProvider/useValidateResetToken.js +42 -0
- package/dist/cjs/authFactory.d.ts +15 -0
- package/dist/cjs/authFactory.d.ts.map +1 -0
- package/dist/cjs/authFactory.js +40 -0
- package/dist/cjs/getCurrentUserFromMiddleware.d.ts +2 -0
- package/dist/cjs/getCurrentUserFromMiddleware.d.ts.map +1 -0
- package/dist/cjs/getCurrentUserFromMiddleware.js +47 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/useAuth.d.ts +6 -0
- package/dist/cjs/useAuth.d.ts.map +1 -0
- package/dist/cjs/useAuth.js +78 -0
- package/dist/getCurrentUserFromMiddleware.d.ts +2 -0
- package/dist/getCurrentUserFromMiddleware.d.ts.map +1 -0
- package/dist/getCurrentUserFromMiddleware.js +23 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/package.json +1 -0
- package/dist/useAuth.d.ts +6 -0
- package/dist/useAuth.d.ts.map +1 -0
- package/dist/useAuth.js +43 -0
- package/package.json +110 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var AuthProviderState_exports = {};
|
20
|
+
__export(AuthProviderState_exports, {
|
21
|
+
middlewareDefaultAuthProviderState: () => middlewareDefaultAuthProviderState,
|
22
|
+
spaDefaultAuthProviderState: () => spaDefaultAuthProviderState
|
23
|
+
});
|
24
|
+
module.exports = __toCommonJS(AuthProviderState_exports);
|
25
|
+
const spaDefaultAuthProviderState = {
|
26
|
+
loading: true,
|
27
|
+
isAuthenticated: false,
|
28
|
+
userMetadata: null,
|
29
|
+
currentUser: null,
|
30
|
+
hasError: false
|
31
|
+
};
|
32
|
+
const middlewareDefaultAuthProviderState = {
|
33
|
+
loading: false,
|
34
|
+
isAuthenticated: false,
|
35
|
+
userMetadata: null,
|
36
|
+
currentUser: null,
|
37
|
+
hasError: false
|
38
|
+
};
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
40
|
+
0 && (module.exports = {
|
41
|
+
middlewareDefaultAuthProviderState,
|
42
|
+
spaDefaultAuthProviderState
|
43
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { ReactNode } from 'react';
|
2
|
+
import React from 'react';
|
3
|
+
import type { AuthProviderState } from './AuthProviderState.js';
|
4
|
+
export type ServerAuthState = AuthProviderState<any> & {
|
5
|
+
cookieHeader: string | null | undefined;
|
6
|
+
roles: string[];
|
7
|
+
};
|
8
|
+
/**
|
9
|
+
* On the server, it resolves to the middlewareDefaultAuthProviderState first.
|
10
|
+
*
|
11
|
+
* On the client it restores from the initial server state injected in the ServerAuthProvider
|
12
|
+
*/
|
13
|
+
export declare const ServerAuthContext: React.Context<ServerAuthState>;
|
14
|
+
/**
|
15
|
+
* Note: This only gets rendered on the server and serves two purposes:
|
16
|
+
* 1) On the server, it sets the auth state
|
17
|
+
* 2) On the client, it restores the auth state from the initial server render
|
18
|
+
*/
|
19
|
+
export declare const ServerAuthProvider: ({ value, children, }: {
|
20
|
+
value: ServerAuthState;
|
21
|
+
children?: ReactNode[];
|
22
|
+
}) => React.JSX.Element;
|
23
|
+
//# sourceMappingURL=ServerAuthProvider.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ServerAuthProvider.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/ServerAuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/D,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG;IAGrD,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IACvC,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB,CAAA;AAkBD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,gCAE7B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,yBAG5B;IACD,KAAK,EAAE,eAAe,CAAA;IACtB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAA;CACvB,sBAmBA,CAAA"}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var ServerAuthProvider_exports = {};
|
30
|
+
__export(ServerAuthProvider_exports, {
|
31
|
+
ServerAuthContext: () => ServerAuthContext,
|
32
|
+
ServerAuthProvider: () => ServerAuthProvider
|
33
|
+
});
|
34
|
+
module.exports = __toCommonJS(ServerAuthProvider_exports);
|
35
|
+
var import_react = __toESM(require("react"), 1);
|
36
|
+
var import_AuthProviderState = require("./AuthProviderState.js");
|
37
|
+
const getAuthInitialStateFromServer = () => {
|
38
|
+
if (globalThis?.__REDWOOD__SERVER__AUTH_STATE__) {
|
39
|
+
const initialState = {
|
40
|
+
...import_AuthProviderState.middlewareDefaultAuthProviderState,
|
41
|
+
encryptedSession: null,
|
42
|
+
...globalThis?.__REDWOOD__SERVER__AUTH_STATE__ || {}
|
43
|
+
};
|
44
|
+
globalThis.__REDWOOD__SERVER__AUTH_STATE__ = null;
|
45
|
+
return initialState;
|
46
|
+
}
|
47
|
+
return null;
|
48
|
+
};
|
49
|
+
const ServerAuthContext = import_react.default.createContext(
|
50
|
+
getAuthInitialStateFromServer()
|
51
|
+
);
|
52
|
+
const ServerAuthProvider = ({
|
53
|
+
value,
|
54
|
+
children
|
55
|
+
}) => {
|
56
|
+
const stringifiedAuthState = `__REDWOOD__SERVER__AUTH_STATE__ = ${JSON.stringify(
|
57
|
+
sanitizeServerAuthState(value)
|
58
|
+
)};`;
|
59
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
|
60
|
+
"script",
|
61
|
+
{
|
62
|
+
id: "__REDWOOD__SERVER_AUTH_STATE__",
|
63
|
+
dangerouslySetInnerHTML: {
|
64
|
+
__html: stringifiedAuthState
|
65
|
+
}
|
66
|
+
}
|
67
|
+
), /* @__PURE__ */ import_react.default.createElement(ServerAuthContext.Provider, { value }, children));
|
68
|
+
};
|
69
|
+
function sanitizeServerAuthState(value) {
|
70
|
+
const sanitizedState = { ...value };
|
71
|
+
delete sanitizedState.cookieHeader;
|
72
|
+
return sanitizedState;
|
73
|
+
}
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
75
|
+
0 && (module.exports = {
|
76
|
+
ServerAuthContext,
|
77
|
+
ServerAuthProvider
|
78
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useCurrentUser.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useCurrentUser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAIlE,eAAO,MAAM,cAAc,uBAAwB,kBAAkB,WAGtC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0B7D,CAAA"}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useCurrentUser_exports = {};
|
20
|
+
__export(useCurrentUser_exports, {
|
21
|
+
useCurrentUser: () => useCurrentUser
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useCurrentUser_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
var import_useToken = require("./useToken.js");
|
26
|
+
const useCurrentUser = (authImplementation) => {
|
27
|
+
const getToken = (0, import_useToken.useToken)(authImplementation);
|
28
|
+
return (0, import_react.useCallback)(async () => {
|
29
|
+
const token = await getToken();
|
30
|
+
const response = await globalThis.fetch(globalThis.RWJS_API_GRAPHQL_URL, {
|
31
|
+
method: "POST",
|
32
|
+
credentials: "include",
|
33
|
+
headers: {
|
34
|
+
"content-type": "application/json",
|
35
|
+
"auth-provider": authImplementation.type,
|
36
|
+
authorization: `Bearer ${token}`
|
37
|
+
},
|
38
|
+
body: JSON.stringify({
|
39
|
+
query: "query __REDWOOD__AUTH_GET_CURRENT_USER { redwood { currentUser } }"
|
40
|
+
})
|
41
|
+
});
|
42
|
+
if (response.ok) {
|
43
|
+
const { data } = await response.json();
|
44
|
+
return data?.redwood?.currentUser;
|
45
|
+
} else {
|
46
|
+
throw new Error(
|
47
|
+
`Could not fetch current user: ${response.statusText} (${response.status})`
|
48
|
+
);
|
49
|
+
}
|
50
|
+
}, [authImplementation, getToken]);
|
51
|
+
};
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
53
|
+
0 && (module.exports = {
|
54
|
+
useCurrentUser
|
55
|
+
});
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
export declare const useForgotPassword: <TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(authImplementation: AuthImplementation<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>) => (username: string) => Promise<TForgotPassword>;
|
3
|
+
//# sourceMappingURL=useForgotPassword.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useForgotPassword.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useForgotPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,eAAO,MAAM,iBAAiB,GAC5B,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,sBAEa,kBAAkB,CACpC,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,CACR,gBAGkB,MAAM,6BAW1B,CAAA"}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useForgotPassword_exports = {};
|
20
|
+
__export(useForgotPassword_exports, {
|
21
|
+
useForgotPassword: () => useForgotPassword
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useForgotPassword_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
const useForgotPassword = (authImplementation) => {
|
26
|
+
return (0, import_react.useCallback)(
|
27
|
+
async (username) => {
|
28
|
+
if (authImplementation.forgotPassword) {
|
29
|
+
return await authImplementation.forgotPassword(username);
|
30
|
+
} else {
|
31
|
+
throw new Error(
|
32
|
+
`Auth client ${authImplementation.type} does not implement this function`
|
33
|
+
);
|
34
|
+
}
|
35
|
+
},
|
36
|
+
[authImplementation]
|
37
|
+
);
|
38
|
+
};
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
40
|
+
0 && (module.exports = {
|
41
|
+
useForgotPassword
|
42
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useHasRole.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useHasRole.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,eAAO,MAAM,UAAU,gBAAiB,WAAW,GAAG,IAAI,oBAevC,MAAM,GAAG,MAAM,EAAE,KAAG,OAiCtC,CAAA"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useHasRole_exports = {};
|
20
|
+
__export(useHasRole_exports, {
|
21
|
+
useHasRole: () => useHasRole
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useHasRole_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
const useHasRole = (currentUser) => {
|
26
|
+
return (0, import_react.useCallback)(
|
27
|
+
(rolesToCheck) => {
|
28
|
+
if (currentUser?.roles) {
|
29
|
+
if (typeof rolesToCheck === "string") {
|
30
|
+
if (typeof currentUser.roles === "string") {
|
31
|
+
return currentUser.roles === rolesToCheck;
|
32
|
+
} else if (Array.isArray(currentUser.roles)) {
|
33
|
+
return currentUser.roles?.some(
|
34
|
+
(allowedRole) => rolesToCheck === allowedRole
|
35
|
+
);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
if (Array.isArray(rolesToCheck)) {
|
39
|
+
if (Array.isArray(currentUser.roles)) {
|
40
|
+
return currentUser.roles?.some(
|
41
|
+
(allowedRole) => rolesToCheck.includes(allowedRole)
|
42
|
+
);
|
43
|
+
} else if (typeof currentUser.roles === "string") {
|
44
|
+
return rolesToCheck.some(
|
45
|
+
(allowedRole) => currentUser?.roles === allowedRole
|
46
|
+
);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return false;
|
51
|
+
},
|
52
|
+
[currentUser]
|
53
|
+
);
|
54
|
+
};
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
56
|
+
0 && (module.exports = {
|
57
|
+
useHasRole
|
58
|
+
});
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
import type { AuthProviderState } from './AuthProviderState.js';
|
3
|
+
import type { useCurrentUser } from './useCurrentUser.js';
|
4
|
+
export declare const useLogIn: <TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(authImplementation: AuthImplementation<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>, setAuthProviderState: React.Dispatch<React.SetStateAction<AuthProviderState<TUser>>>, getCurrentUser: ReturnType<typeof useCurrentUser>) => (options?: TLogInOptions) => Promise<TLogIn>;
|
5
|
+
//# sourceMappingURL=useLogIn.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useLogIn.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useLogIn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGzD,eAAO,MAAM,QAAQ,GACnB,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,sBAEa,kBAAkB,CACpC,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,CACR,wBACqB,KAAK,CAAC,QAAQ,CAClC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAC/C,kBACe,UAAU,CAAC,OAAO,cAAc,CAAC,gBAS9B,aAAa,oBASjC,CAAA"}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useLogIn_exports = {};
|
20
|
+
__export(useLogIn_exports, {
|
21
|
+
useLogIn: () => useLogIn
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useLogIn_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
var import_AuthProviderState = require("./AuthProviderState.js");
|
26
|
+
var import_useReauthenticate = require("./useReauthenticate.js");
|
27
|
+
const useLogIn = (authImplementation, setAuthProviderState, getCurrentUser) => {
|
28
|
+
const reauthenticate = (0, import_useReauthenticate.useReauthenticate)(
|
29
|
+
authImplementation,
|
30
|
+
setAuthProviderState,
|
31
|
+
getCurrentUser
|
32
|
+
);
|
33
|
+
return (0, import_react.useCallback)(
|
34
|
+
async (options) => {
|
35
|
+
setAuthProviderState(import_AuthProviderState.spaDefaultAuthProviderState);
|
36
|
+
const loginResult = await authImplementation.login(options);
|
37
|
+
await reauthenticate();
|
38
|
+
return loginResult;
|
39
|
+
},
|
40
|
+
[authImplementation, reauthenticate, setAuthProviderState]
|
41
|
+
);
|
42
|
+
};
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
44
|
+
0 && (module.exports = {
|
45
|
+
useLogIn
|
46
|
+
});
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
import type { AuthProviderState } from './AuthProviderState.js';
|
3
|
+
export declare const useLogOut: <TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(authImplementation: AuthImplementation<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>, setAuthProviderState: React.Dispatch<React.SetStateAction<AuthProviderState<TUser>>>) => (options?: TLogOutOptions) => Promise<TLogOut>;
|
4
|
+
//# sourceMappingURL=useLogOut.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useLogOut.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useLogOut.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,eAAO,MAAM,SAAS,GACpB,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,sBAEa,kBAAkB,CACpC,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,CACR,wBACqB,KAAK,CAAC,QAAQ,CAClC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAC/C,gBAGkB,cAAc,qBAgBlC,CAAA"}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useLogOut_exports = {};
|
20
|
+
__export(useLogOut_exports, {
|
21
|
+
useLogOut: () => useLogOut
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useLogOut_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
const useLogOut = (authImplementation, setAuthProviderState) => {
|
26
|
+
return (0, import_react.useCallback)(
|
27
|
+
async (options) => {
|
28
|
+
const logoutOutput = await authImplementation.logout(options);
|
29
|
+
setAuthProviderState({
|
30
|
+
userMetadata: null,
|
31
|
+
currentUser: null,
|
32
|
+
isAuthenticated: false,
|
33
|
+
hasError: false,
|
34
|
+
error: void 0,
|
35
|
+
loading: false
|
36
|
+
});
|
37
|
+
return logoutOutput;
|
38
|
+
},
|
39
|
+
[authImplementation, setAuthProviderState]
|
40
|
+
);
|
41
|
+
};
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
43
|
+
0 && (module.exports = {
|
44
|
+
useLogOut
|
45
|
+
});
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
import type { AuthProviderState } from './AuthProviderState.js';
|
3
|
+
import type { useCurrentUser } from './useCurrentUser.js';
|
4
|
+
export declare const useReauthenticate: <TUser>(authImplementation: AuthImplementation<TUser>, setAuthProviderState: React.Dispatch<React.SetStateAction<AuthProviderState<TUser>>>, getCurrentUser: ReturnType<typeof useCurrentUser>) => () => Promise<void>;
|
5
|
+
//# sourceMappingURL=useReauthenticate.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useReauthenticate.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useReauthenticate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAWzD,eAAO,MAAM,iBAAiB,GAAI,KAAK,sBACjB,kBAAkB,CAAC,KAAK,CAAC,wBACvB,KAAK,CAAC,QAAQ,CAClC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAC/C,kBACe,UAAU,CAAC,OAAO,cAAc,CAAC,wBA0DlD,CAAA"}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useReauthenticate_exports = {};
|
20
|
+
__export(useReauthenticate_exports, {
|
21
|
+
useReauthenticate: () => useReauthenticate
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useReauthenticate_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
var import_useToken = require("./useToken.js");
|
26
|
+
const notAuthenticatedState = {
|
27
|
+
isAuthenticated: false,
|
28
|
+
currentUser: null,
|
29
|
+
userMetadata: null,
|
30
|
+
loading: false,
|
31
|
+
hasError: false
|
32
|
+
};
|
33
|
+
const useReauthenticate = (authImplementation, setAuthProviderState, getCurrentUser) => {
|
34
|
+
const getToken = (0, import_useToken.useToken)(authImplementation);
|
35
|
+
return (0, import_react.useCallback)(async () => {
|
36
|
+
if (authImplementation.loadWhileReauthenticating) {
|
37
|
+
setAuthProviderState((oldState) => ({
|
38
|
+
...oldState,
|
39
|
+
loading: true
|
40
|
+
}));
|
41
|
+
}
|
42
|
+
try {
|
43
|
+
const token = await getToken();
|
44
|
+
let currentUser;
|
45
|
+
if (token || authImplementation.middlewareAuthEnabled) {
|
46
|
+
currentUser = await getCurrentUser();
|
47
|
+
}
|
48
|
+
if (!currentUser) {
|
49
|
+
let loading = false;
|
50
|
+
if (authImplementation.clientHasLoaded) {
|
51
|
+
loading = !authImplementation.clientHasLoaded();
|
52
|
+
}
|
53
|
+
setAuthProviderState({
|
54
|
+
...notAuthenticatedState,
|
55
|
+
loading,
|
56
|
+
client: authImplementation.client
|
57
|
+
});
|
58
|
+
} else {
|
59
|
+
const userMetadata = await authImplementation.getUserMetadata();
|
60
|
+
setAuthProviderState((oldState) => ({
|
61
|
+
...oldState,
|
62
|
+
userMetadata,
|
63
|
+
currentUser,
|
64
|
+
isAuthenticated: !!currentUser,
|
65
|
+
loading: false,
|
66
|
+
client: authImplementation.client
|
67
|
+
}));
|
68
|
+
}
|
69
|
+
} catch (e) {
|
70
|
+
setAuthProviderState({
|
71
|
+
...notAuthenticatedState,
|
72
|
+
hasError: true,
|
73
|
+
error: e
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}, [authImplementation, setAuthProviderState, getToken, getCurrentUser]);
|
77
|
+
};
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
79
|
+
0 && (module.exports = {
|
80
|
+
useReauthenticate
|
81
|
+
});
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
export declare const useResetPassword: <TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(authImplementation: AuthImplementation<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>) => (options?: TResetPasswordOptions) => Promise<TResetPassword>;
|
3
|
+
//# sourceMappingURL=useResetPassword.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useResetPassword.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useResetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,eAAO,MAAM,gBAAgB,GAC3B,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,sBAEa,kBAAkB,CACpC,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,CACR,gBAGkB,qBAAqB,4BAWzC,CAAA"}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useResetPassword_exports = {};
|
20
|
+
__export(useResetPassword_exports, {
|
21
|
+
useResetPassword: () => useResetPassword
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useResetPassword_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
const useResetPassword = (authImplementation) => {
|
26
|
+
return (0, import_react.useCallback)(
|
27
|
+
async (options) => {
|
28
|
+
if (authImplementation.resetPassword) {
|
29
|
+
return await authImplementation.resetPassword(options);
|
30
|
+
} else {
|
31
|
+
throw new Error(
|
32
|
+
`Auth client ${authImplementation.type} does not implement this function`
|
33
|
+
);
|
34
|
+
}
|
35
|
+
},
|
36
|
+
[authImplementation]
|
37
|
+
);
|
38
|
+
};
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
40
|
+
0 && (module.exports = {
|
41
|
+
useResetPassword
|
42
|
+
});
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
import type { AuthProviderState } from './AuthProviderState.js';
|
3
|
+
import type { useCurrentUser } from './useCurrentUser.js';
|
4
|
+
export declare const useSignUp: <TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(authImplementation: AuthImplementation<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>, setAuthProviderState: React.Dispatch<React.SetStateAction<AuthProviderState<TUser>>>, getCurrentUser: ReturnType<typeof useCurrentUser>) => (options?: TSignUpOptions) => Promise<TSignUp>;
|
5
|
+
//# sourceMappingURL=useSignUp.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useSignUp.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/useSignUp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGzD,eAAO,MAAM,SAAS,GACpB,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,sBAEa,kBAAkB,CACpC,KAAK,EACL,YAAY,EACZ,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,CACR,wBACqB,KAAK,CAAC,QAAQ,CAClC,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAC/C,kBACe,UAAU,CAAC,OAAO,cAAc,CAAC,gBAS9B,cAAc,qBAOlC,CAAA"}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var useSignUp_exports = {};
|
20
|
+
__export(useSignUp_exports, {
|
21
|
+
useSignUp: () => useSignUp
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(useSignUp_exports);
|
24
|
+
var import_react = require("react");
|
25
|
+
var import_useReauthenticate = require("./useReauthenticate.js");
|
26
|
+
const useSignUp = (authImplementation, setAuthProviderState, getCurrentUser) => {
|
27
|
+
const reauthenticate = (0, import_useReauthenticate.useReauthenticate)(
|
28
|
+
authImplementation,
|
29
|
+
setAuthProviderState,
|
30
|
+
getCurrentUser
|
31
|
+
);
|
32
|
+
return (0, import_react.useCallback)(
|
33
|
+
async (options) => {
|
34
|
+
const signupOutput = await authImplementation.signup(options);
|
35
|
+
await reauthenticate();
|
36
|
+
return signupOutput;
|
37
|
+
},
|
38
|
+
[authImplementation, reauthenticate]
|
39
|
+
);
|
40
|
+
};
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
42
|
+
0 && (module.exports = {
|
43
|
+
useSignUp
|
44
|
+
});
|