@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,22 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
import { spaDefaultAuthProviderState } from "./AuthProviderState.js";
|
3
|
+
import { useReauthenticate } from "./useReauthenticate.js";
|
4
|
+
const useLogIn = (authImplementation, setAuthProviderState, getCurrentUser) => {
|
5
|
+
const reauthenticate = useReauthenticate(
|
6
|
+
authImplementation,
|
7
|
+
setAuthProviderState,
|
8
|
+
getCurrentUser
|
9
|
+
);
|
10
|
+
return useCallback(
|
11
|
+
async (options) => {
|
12
|
+
setAuthProviderState(spaDefaultAuthProviderState);
|
13
|
+
const loginResult = await authImplementation.login(options);
|
14
|
+
await reauthenticate();
|
15
|
+
return loginResult;
|
16
|
+
},
|
17
|
+
[authImplementation, reauthenticate, setAuthProviderState]
|
18
|
+
);
|
19
|
+
};
|
20
|
+
export {
|
21
|
+
useLogIn
|
22
|
+
};
|
@@ -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,21 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
const useLogOut = (authImplementation, setAuthProviderState) => {
|
3
|
+
return useCallback(
|
4
|
+
async (options) => {
|
5
|
+
const logoutOutput = await authImplementation.logout(options);
|
6
|
+
setAuthProviderState({
|
7
|
+
userMetadata: null,
|
8
|
+
currentUser: null,
|
9
|
+
isAuthenticated: false,
|
10
|
+
hasError: false,
|
11
|
+
error: void 0,
|
12
|
+
loading: false
|
13
|
+
});
|
14
|
+
return logoutOutput;
|
15
|
+
},
|
16
|
+
[authImplementation, setAuthProviderState]
|
17
|
+
);
|
18
|
+
};
|
19
|
+
export {
|
20
|
+
useLogOut
|
21
|
+
};
|
@@ -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,57 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
import { useToken } from "./useToken.js";
|
3
|
+
const notAuthenticatedState = {
|
4
|
+
isAuthenticated: false,
|
5
|
+
currentUser: null,
|
6
|
+
userMetadata: null,
|
7
|
+
loading: false,
|
8
|
+
hasError: false
|
9
|
+
};
|
10
|
+
const useReauthenticate = (authImplementation, setAuthProviderState, getCurrentUser) => {
|
11
|
+
const getToken = useToken(authImplementation);
|
12
|
+
return useCallback(async () => {
|
13
|
+
if (authImplementation.loadWhileReauthenticating) {
|
14
|
+
setAuthProviderState((oldState) => ({
|
15
|
+
...oldState,
|
16
|
+
loading: true
|
17
|
+
}));
|
18
|
+
}
|
19
|
+
try {
|
20
|
+
const token = await getToken();
|
21
|
+
let currentUser;
|
22
|
+
if (token || authImplementation.middlewareAuthEnabled) {
|
23
|
+
currentUser = await getCurrentUser();
|
24
|
+
}
|
25
|
+
if (!currentUser) {
|
26
|
+
let loading = false;
|
27
|
+
if (authImplementation.clientHasLoaded) {
|
28
|
+
loading = !authImplementation.clientHasLoaded();
|
29
|
+
}
|
30
|
+
setAuthProviderState({
|
31
|
+
...notAuthenticatedState,
|
32
|
+
loading,
|
33
|
+
client: authImplementation.client
|
34
|
+
});
|
35
|
+
} else {
|
36
|
+
const userMetadata = await authImplementation.getUserMetadata();
|
37
|
+
setAuthProviderState((oldState) => ({
|
38
|
+
...oldState,
|
39
|
+
userMetadata,
|
40
|
+
currentUser,
|
41
|
+
isAuthenticated: !!currentUser,
|
42
|
+
loading: false,
|
43
|
+
client: authImplementation.client
|
44
|
+
}));
|
45
|
+
}
|
46
|
+
} catch (e) {
|
47
|
+
setAuthProviderState({
|
48
|
+
...notAuthenticatedState,
|
49
|
+
hasError: true,
|
50
|
+
error: e
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}, [authImplementation, setAuthProviderState, getToken, getCurrentUser]);
|
54
|
+
};
|
55
|
+
export {
|
56
|
+
useReauthenticate
|
57
|
+
};
|
@@ -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,18 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
const useResetPassword = (authImplementation) => {
|
3
|
+
return useCallback(
|
4
|
+
async (options) => {
|
5
|
+
if (authImplementation.resetPassword) {
|
6
|
+
return await authImplementation.resetPassword(options);
|
7
|
+
} else {
|
8
|
+
throw new Error(
|
9
|
+
`Auth client ${authImplementation.type} does not implement this function`
|
10
|
+
);
|
11
|
+
}
|
12
|
+
},
|
13
|
+
[authImplementation]
|
14
|
+
);
|
15
|
+
};
|
16
|
+
export {
|
17
|
+
useResetPassword
|
18
|
+
};
|
@@ -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,20 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
import { useReauthenticate } from "./useReauthenticate.js";
|
3
|
+
const useSignUp = (authImplementation, setAuthProviderState, getCurrentUser) => {
|
4
|
+
const reauthenticate = useReauthenticate(
|
5
|
+
authImplementation,
|
6
|
+
setAuthProviderState,
|
7
|
+
getCurrentUser
|
8
|
+
);
|
9
|
+
return useCallback(
|
10
|
+
async (options) => {
|
11
|
+
const signupOutput = await authImplementation.signup(options);
|
12
|
+
await reauthenticate();
|
13
|
+
return signupOutput;
|
14
|
+
},
|
15
|
+
[authImplementation, reauthenticate]
|
16
|
+
);
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
useSignUp
|
20
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useToken.d.ts","sourceRoot":"","sources":["../../src/AuthProvider/useToken.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,eAAO,MAAM,QAAQ,uBAAwB,kBAAkB,iCAgB9D,CAAA"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
const useToken = (authImplementation) => {
|
3
|
+
return useCallback(async () => {
|
4
|
+
try {
|
5
|
+
const token = await authImplementation.getToken();
|
6
|
+
return token;
|
7
|
+
} catch (e) {
|
8
|
+
console.error("Caught internal:", e);
|
9
|
+
return null;
|
10
|
+
}
|
11
|
+
}, [authImplementation]);
|
12
|
+
};
|
13
|
+
export {
|
14
|
+
useToken
|
15
|
+
};
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
2
|
+
export declare const useValidateResetToken: <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>) => (resetToken: string | null) => Promise<TValidateResetToken>;
|
3
|
+
//# sourceMappingURL=useValidateResetToken.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useValidateResetToken.d.ts","sourceRoot":"","sources":["../../src/AuthProvider/useValidateResetToken.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAElE,eAAO,MAAM,qBAAqB,GAChC,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,kBAGoB,MAAM,GAAG,IAAI,iCAWnC,CAAA"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { useCallback } from "react";
|
2
|
+
const useValidateResetToken = (authImplementation) => {
|
3
|
+
return useCallback(
|
4
|
+
async (resetToken) => {
|
5
|
+
if (authImplementation.validateResetToken) {
|
6
|
+
return await authImplementation.validateResetToken(resetToken);
|
7
|
+
} else {
|
8
|
+
throw new Error(
|
9
|
+
`Auth client ${authImplementation.type} does not implement this function`
|
10
|
+
);
|
11
|
+
}
|
12
|
+
},
|
13
|
+
[authImplementation]
|
14
|
+
);
|
15
|
+
};
|
16
|
+
export {
|
17
|
+
useValidateResetToken
|
18
|
+
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import type { CurrentUser } from './AuthContext.js';
|
2
|
+
import type { AuthImplementation } from './AuthImplementation.js';
|
3
|
+
export type CustomProviderHooks = {
|
4
|
+
useCurrentUser?: () => Promise<CurrentUser>;
|
5
|
+
useHasRole?: (currentUser: CurrentUser | null) => (rolesToCheck: string | string[]) => boolean;
|
6
|
+
};
|
7
|
+
export declare function createAuthentication<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>, customProviderHooks?: {
|
8
|
+
useCurrentUser?: () => Promise<CurrentUser>;
|
9
|
+
useHasRole?: (currentUser: CurrentUser | null) => (rolesToCheck: string | string[]) => boolean;
|
10
|
+
}): {
|
11
|
+
AuthContext: import("react").Context<import("./AuthContext.js").AuthContextInterface<TUser, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient> | undefined>;
|
12
|
+
AuthProvider: ({ children }: import("./AuthProvider/AuthProvider.js").AuthProviderProps) => import("react").JSX.Element;
|
13
|
+
useAuth: () => import("./AuthContext.js").AuthContextInterface<TUser, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>;
|
14
|
+
};
|
15
|
+
//# sourceMappingURL=authFactory.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"authFactory.d.ts","sourceRoot":"","sources":["../src/authFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAIjE,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;IAC3C,UAAU,CAAC,EAAE,CACX,WAAW,EAAE,WAAW,GAAG,IAAI,KAC5B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAA;CAClD,CAAA;AAED,wBAAgB,oBAAoB,CAClC,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,EAEP,kBAAkB,EAAE,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,EACD,mBAAmB,CAAC,EAAE;IACpB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;IAC3C,UAAU,CAAC,EAAE,CACX,WAAW,EAAE,WAAW,GAAG,IAAI,KAC5B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAA;CAClD;;;;EAwBF"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { createAuthContext } from "./AuthContext.js";
|
2
|
+
import { createAuthProvider } from "./AuthProvider/AuthProvider.js";
|
3
|
+
import { createUseAuth } from "./useAuth.js";
|
4
|
+
function createAuthentication(authImplementation, customProviderHooks) {
|
5
|
+
const AuthContext = createAuthContext();
|
6
|
+
const useAuth = createUseAuth(AuthContext);
|
7
|
+
const AuthProvider = createAuthProvider(
|
8
|
+
AuthContext,
|
9
|
+
authImplementation,
|
10
|
+
customProviderHooks
|
11
|
+
);
|
12
|
+
return { AuthContext, AuthProvider, useAuth };
|
13
|
+
}
|
14
|
+
export {
|
15
|
+
createAuthentication
|
16
|
+
};
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface CurrentUser {
|
3
|
+
[key: string]: unknown;
|
4
|
+
}
|
5
|
+
export interface AuthContextInterface<TUser, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient> {
|
6
|
+
/** Determining your current authentication state */
|
7
|
+
loading: boolean;
|
8
|
+
isAuthenticated: boolean;
|
9
|
+
/** The current user's data from the `getCurrentUser` function on the api side */
|
10
|
+
currentUser: null | CurrentUser;
|
11
|
+
/**
|
12
|
+
* The user's metadata from the auth service provider
|
13
|
+
*
|
14
|
+
* Exactly what this looks like will depend on the auth service provider,
|
15
|
+
* but one example is this
|
16
|
+
* ```json
|
17
|
+
* {
|
18
|
+
* "id": "11111111-2222-3333-4444-5555555555555",
|
19
|
+
* "aud": "authenticated",
|
20
|
+
* "role": "authenticated",
|
21
|
+
* "email": "email@example.com",
|
22
|
+
* "app_metadata": {
|
23
|
+
* "provider": "email"
|
24
|
+
* },
|
25
|
+
* "user_metadata": null,
|
26
|
+
* "created_at": "2016-05-15T19:53:12.368652374-07:00",
|
27
|
+
* "updated_at": "2016-05-15T19:53:12.368652374-07:00"
|
28
|
+
* }
|
29
|
+
* ```
|
30
|
+
*/
|
31
|
+
userMetadata: null | TUser;
|
32
|
+
logIn(options?: TLogInOptions): Promise<TLogIn>;
|
33
|
+
logOut(options?: TLogOutOptions): Promise<TLogOut>;
|
34
|
+
signUp(options?: TSignUpOptions): Promise<TSignUp>;
|
35
|
+
/**
|
36
|
+
* Clients should always return null or string
|
37
|
+
* It is expected that they catch any errors internally
|
38
|
+
*/
|
39
|
+
getToken(): Promise<null | string>;
|
40
|
+
/**
|
41
|
+
* Fetches the "currentUser" from the api side,
|
42
|
+
* but does not update the current user state.
|
43
|
+
*/
|
44
|
+
getCurrentUser(): Promise<null | CurrentUser>;
|
45
|
+
/**
|
46
|
+
* Checks if the "currentUser" from the api side
|
47
|
+
* is assigned a role or one of a list of roles.
|
48
|
+
* If the user is assigned any of the provided list of roles,
|
49
|
+
* the hasRole is considered to be true.
|
50
|
+
**/
|
51
|
+
hasRole(rolesToCheck: string | string[]): boolean;
|
52
|
+
/**
|
53
|
+
* Redetermine authentication state and update the state.
|
54
|
+
*/
|
55
|
+
reauthenticate(): Promise<void>;
|
56
|
+
forgotPassword(username: string): Promise<TForgotPassword>;
|
57
|
+
resetPassword(options?: TResetPasswordOptions): Promise<TResetPassword>;
|
58
|
+
validateResetToken(resetToken: string | null): Promise<TValidateResetToken>;
|
59
|
+
/**
|
60
|
+
* A reference to auth service provider sdk "client", which is useful if we
|
61
|
+
* do not support some specific functionality.
|
62
|
+
*/
|
63
|
+
client?: TClient;
|
64
|
+
type: string;
|
65
|
+
hasError: boolean;
|
66
|
+
error?: Error;
|
67
|
+
}
|
68
|
+
export declare function createAuthContext<TUser, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(): React.Context<AuthContextInterface<TUser, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient> | undefined>;
|
69
|
+
//# sourceMappingURL=AuthContext.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../src/AuthContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB,CACnC,KAAK,EACL,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO;IAEP,oDAAoD;IACpD,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,OAAO,CAAA;IACxB,iFAAiF;IACjF,WAAW,EAAE,IAAI,GAAG,WAAW,CAAA;IAC/B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,YAAY,EAAE,IAAI,GAAG,KAAK,CAAA;IAC1B,KAAK,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC/C,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAClD,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAClD;;;OAGG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAAA;IAClC;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,CAAA;IAC7C;;;;;QAKI;IACJ,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAA;IACjD;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAC1D,aAAa,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACvE,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAC3E;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EACL,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,2NAmBR"}
|
@@ -0,0 +1,41 @@
|
|
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 AuthContext_exports = {};
|
30
|
+
__export(AuthContext_exports, {
|
31
|
+
createAuthContext: () => createAuthContext
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(AuthContext_exports);
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
35
|
+
function createAuthContext() {
|
36
|
+
return import_react.default.createContext(void 0);
|
37
|
+
}
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
39
|
+
0 && (module.exports = {
|
40
|
+
createAuthContext
|
41
|
+
});
|
@@ -0,0 +1,49 @@
|
|
1
|
+
export interface AuthImplementation<TUser = unknown, TRestoreAuth = unknown, TLogInOptions = unknown, TLogIn = unknown, TLogOutOptions = unknown, TLogOut = unknown, TSignUpOptions = unknown, TSignUp = unknown, TForgotPassword = unknown, TResetPasswordOptions = unknown, TResetPassword = unknown, TValidateResetToken = unknown, TClient = unknown> {
|
2
|
+
type: string;
|
3
|
+
client?: TClient;
|
4
|
+
restoreAuthState?(): Promise<TRestoreAuth>;
|
5
|
+
login(options?: TLogInOptions): Promise<TLogIn>;
|
6
|
+
logout(options?: TLogOutOptions): Promise<TLogOut>;
|
7
|
+
signup(options?: TSignUpOptions): Promise<TSignUp>;
|
8
|
+
getToken(): Promise<string | null>;
|
9
|
+
forgotPassword?(username: string): Promise<TForgotPassword>;
|
10
|
+
resetPassword?(options?: TResetPasswordOptions): Promise<TResetPassword>;
|
11
|
+
validateResetToken?(token: string | null): Promise<TValidateResetToken>;
|
12
|
+
clientHasLoaded?(): boolean;
|
13
|
+
/**
|
14
|
+
* The user's data from the AuthProvider
|
15
|
+
*
|
16
|
+
* Exactly what this looks like will depend on the auth service provider,
|
17
|
+
* but one example is this
|
18
|
+
* ```json
|
19
|
+
* {
|
20
|
+
* "id": "11111111-2222-3333-4444-5555555555555",
|
21
|
+
* "aud": "authenticated",
|
22
|
+
* "role": "authenticated",
|
23
|
+
* "email": "email@example.com",
|
24
|
+
* "app_metadata": {
|
25
|
+
* "provider": "email"
|
26
|
+
* },
|
27
|
+
* "user_metadata": null,
|
28
|
+
* "created_at": "2016-05-15T19:53:12.368652374-07:00",
|
29
|
+
* "updated_at": "2016-05-15T19:53:12.368652374-07:00"
|
30
|
+
* }
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
getUserMetadata(): Promise<TUser | null>;
|
34
|
+
/**
|
35
|
+
* Set "loading" to true while the auth provider is reauthenticating.
|
36
|
+
*/
|
37
|
+
loadWhileReauthenticating?: boolean;
|
38
|
+
/**
|
39
|
+
* This property is either manually set by the user, or inferred from the
|
40
|
+
* experimental.streamingSsr setting in TOML
|
41
|
+
*/
|
42
|
+
middlewareAuthEnabled?: boolean;
|
43
|
+
/**
|
44
|
+
* This is the endpoint on the middleware we are going to hit for POST
|
45
|
+
* requests
|
46
|
+
*/
|
47
|
+
getAuthUrl?: () => string;
|
48
|
+
}
|
49
|
+
//# sourceMappingURL=AuthImplementation.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AuthImplementation.d.ts","sourceRoot":"","sources":["../../src/AuthImplementation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB,CACjC,KAAK,GAAG,OAAO,EACf,YAAY,GAAG,OAAO,EACtB,aAAa,GAAG,OAAO,EACvB,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO,EACxB,OAAO,GAAG,OAAO,EACjB,cAAc,GAAG,OAAO,EACxB,OAAO,GAAG,OAAO,EACjB,eAAe,GAAG,OAAO,EACzB,qBAAqB,GAAG,OAAO,EAC/B,cAAc,GAAG,OAAO,EACxB,mBAAmB,GAAG,OAAO,EAC7B,OAAO,GAAG,OAAO;IAEjB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB,gBAAgB,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,CAAA;IAC1C,KAAK,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAC/C,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAClD,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAClD,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;IAClC,cAAc,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3D,aAAa,CAAC,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACxE,kBAAkB,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;IACvE,eAAe,CAAC,IAAI,OAAO,CAAA;IAE3B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;IAExC;;OAEG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;IAEnC;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,MAAM,CAAA;CAC1B"}
|
@@ -0,0 +1,16 @@
|
|
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 __copyProps = (to, from, except, desc) => {
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
for (let key of __getOwnPropNames(from))
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
11
|
+
}
|
12
|
+
return to;
|
13
|
+
};
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
15
|
+
var AuthImplementation_exports = {};
|
16
|
+
module.exports = __toCommonJS(AuthImplementation_exports);
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ReactNode } from 'react';
|
2
|
+
import React from 'react';
|
3
|
+
import type { AuthContextInterface, CurrentUser } from '../AuthContext.js';
|
4
|
+
import type { AuthImplementation } from '../AuthImplementation.js';
|
5
|
+
export interface AuthProviderProps {
|
6
|
+
children: ReactNode;
|
7
|
+
}
|
8
|
+
export declare function createAuthProvider<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>(AuthContext: React.Context<AuthContextInterface<TUser, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient> | undefined>, authImplementation: AuthImplementation<TUser, TRestoreAuth, TLogInOptions, TLogIn, TLogOutOptions, TLogOut, TSignUpOptions, TSignUp, TForgotPassword, TResetPasswordOptions, TResetPassword, TValidateResetToken, TClient>, customProviderHooks?: {
|
9
|
+
useCurrentUser?: () => Promise<CurrentUser>;
|
10
|
+
useHasRole?: (currentUser: CurrentUser | null) => (rolesToCheck: string | string[]) => boolean;
|
11
|
+
}): ({ children }: AuthProviderProps) => React.JSX.Element;
|
12
|
+
//# sourceMappingURL=AuthProvider.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/AuthProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAA0C,MAAM,OAAO,CAAA;AAE9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAgBlE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,kBAAkB,CAChC,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,EAEP,WAAW,EAAE,KAAK,CAAC,OAAO,CACtB,oBAAoB,CAClB,KAAK,EACL,aAAa,EACb,MAAM,EACN,cAAc,EACd,OAAO,EACP,cAAc,EACd,OAAO,EACP,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,OAAO,CACR,GACD,SAAS,CACZ,EACD,kBAAkB,EAAE,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,EACD,mBAAmB,CAAC,EAAE;IACpB,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;IAC3C,UAAU,CAAC,EAAE,CACX,WAAW,EAAE,WAAW,GAAG,IAAI,KAC5B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAA;CAClD,kBAEmC,iBAAiB,uBA4FtD"}
|
@@ -0,0 +1,117 @@
|
|
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 AuthProvider_exports = {};
|
30
|
+
__export(AuthProvider_exports, {
|
31
|
+
createAuthProvider: () => createAuthProvider
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(AuthProvider_exports);
|
34
|
+
var import_react = __toESM(require("react"), 1);
|
35
|
+
var import_AuthProviderState = require("./AuthProviderState.js");
|
36
|
+
var import_ServerAuthProvider = require("./ServerAuthProvider.js");
|
37
|
+
var import_useCurrentUser = require("./useCurrentUser.js");
|
38
|
+
var import_useForgotPassword = require("./useForgotPassword.js");
|
39
|
+
var import_useHasRole = require("./useHasRole.js");
|
40
|
+
var import_useLogIn = require("./useLogIn.js");
|
41
|
+
var import_useLogOut = require("./useLogOut.js");
|
42
|
+
var import_useReauthenticate = require("./useReauthenticate.js");
|
43
|
+
var import_useResetPassword = require("./useResetPassword.js");
|
44
|
+
var import_useSignUp = require("./useSignUp.js");
|
45
|
+
var import_useToken = require("./useToken.js");
|
46
|
+
var import_useValidateResetToken = require("./useValidateResetToken.js");
|
47
|
+
function createAuthProvider(AuthContext, authImplementation, customProviderHooks) {
|
48
|
+
const AuthProvider = ({ children }) => {
|
49
|
+
const serverAuthState = (0, import_react.useContext)(import_ServerAuthProvider.ServerAuthContext);
|
50
|
+
const [authProviderState, setAuthProviderState] = (0, import_react.useState)(serverAuthState || import_AuthProviderState.spaDefaultAuthProviderState);
|
51
|
+
const getToken = (0, import_useToken.useToken)(authImplementation);
|
52
|
+
const getCurrentUser = customProviderHooks?.useCurrentUser ? customProviderHooks.useCurrentUser : (
|
53
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
54
|
+
(0, import_useCurrentUser.useCurrentUser)(authImplementation)
|
55
|
+
);
|
56
|
+
const reauthenticate = (0, import_useReauthenticate.useReauthenticate)(
|
57
|
+
authImplementation,
|
58
|
+
setAuthProviderState,
|
59
|
+
getCurrentUser
|
60
|
+
);
|
61
|
+
const hasRole = customProviderHooks?.useHasRole ? customProviderHooks.useHasRole(authProviderState.currentUser) : (
|
62
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
63
|
+
(0, import_useHasRole.useHasRole)(authProviderState.currentUser)
|
64
|
+
);
|
65
|
+
const signUp = (0, import_useSignUp.useSignUp)(
|
66
|
+
authImplementation,
|
67
|
+
setAuthProviderState,
|
68
|
+
getCurrentUser
|
69
|
+
);
|
70
|
+
const logIn = (0, import_useLogIn.useLogIn)(
|
71
|
+
authImplementation,
|
72
|
+
setAuthProviderState,
|
73
|
+
getCurrentUser
|
74
|
+
);
|
75
|
+
const logOut = (0, import_useLogOut.useLogOut)(authImplementation, setAuthProviderState);
|
76
|
+
const forgotPassword = (0, import_useForgotPassword.useForgotPassword)(authImplementation);
|
77
|
+
const resetPassword = (0, import_useResetPassword.useResetPassword)(authImplementation);
|
78
|
+
const validateResetToken = (0, import_useValidateResetToken.useValidateResetToken)(authImplementation);
|
79
|
+
const type = authImplementation.type;
|
80
|
+
const client = authImplementation.client;
|
81
|
+
(0, import_react.useEffect)(() => {
|
82
|
+
async function doRestoreState() {
|
83
|
+
await authImplementation.restoreAuthState?.();
|
84
|
+
if (!serverAuthState) {
|
85
|
+
reauthenticate();
|
86
|
+
}
|
87
|
+
}
|
88
|
+
doRestoreState();
|
89
|
+
}, [reauthenticate, serverAuthState]);
|
90
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
91
|
+
AuthContext.Provider,
|
92
|
+
{
|
93
|
+
value: {
|
94
|
+
...authProviderState,
|
95
|
+
signUp,
|
96
|
+
logIn,
|
97
|
+
logOut,
|
98
|
+
getToken,
|
99
|
+
getCurrentUser,
|
100
|
+
hasRole,
|
101
|
+
reauthenticate,
|
102
|
+
forgotPassword,
|
103
|
+
resetPassword,
|
104
|
+
validateResetToken,
|
105
|
+
client,
|
106
|
+
type
|
107
|
+
}
|
108
|
+
},
|
109
|
+
children
|
110
|
+
);
|
111
|
+
};
|
112
|
+
return AuthProvider;
|
113
|
+
}
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
115
|
+
0 && (module.exports = {
|
116
|
+
createAuthProvider
|
117
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { CurrentUser } from '../AuthContext.js';
|
2
|
+
export type AuthProviderState<TUser, TClient = unknown> = {
|
3
|
+
loading: boolean;
|
4
|
+
isAuthenticated: boolean;
|
5
|
+
userMetadata: null | TUser;
|
6
|
+
currentUser: null | CurrentUser;
|
7
|
+
hasError: boolean;
|
8
|
+
error?: Error;
|
9
|
+
client?: TClient;
|
10
|
+
};
|
11
|
+
export declare const spaDefaultAuthProviderState: AuthProviderState<never>;
|
12
|
+
export declare const middlewareDefaultAuthProviderState: AuthProviderState<never>;
|
13
|
+
//# sourceMappingURL=AuthProviderState.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AuthProviderState.d.ts","sourceRoot":"","sources":["../../../src/AuthProvider/AuthProviderState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,MAAM,MAAM,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,IAAI;IACxD,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,EAAE,OAAO,CAAA;IACxB,YAAY,EAAE,IAAI,GAAG,KAAK,CAAA;IAC1B,WAAW,EAAE,IAAI,GAAG,WAAW,CAAA;IAC/B,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,2BAA2B,EAAE,iBAAiB,CAAC,KAAK,CAMhE,CAAA;AAED,eAAO,MAAM,kCAAkC,EAAE,iBAAiB,CAAC,KAAK,CAMvE,CAAA"}
|