-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.browser.ts
59 lines (56 loc) · 2.13 KB
/
index.browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { InitAuth0, SignInWithAuth0 } from './instance';
import { GetAccessToken, GetSession } from './session';
import { WithApiAuthRequired } from './helpers';
import { HandleAuth, HandleCallback, HandleLogin, HandleLogout, HandleProfile } from './handlers';
export {
UserProvider,
UserProviderProps,
UserProfile,
UserContext,
RequestError,
useUser,
withPageAuthRequired,
WithPageAuthRequired
} from './frontend';
const serverSideOnly = (method: string): string => `The ${method} method can only be used from the server side`;
const instance: SignInWithAuth0 = {
getSession() {
throw new Error(serverSideOnly('getSession'));
},
getAccessToken() {
throw new Error(serverSideOnly('getAccessToken'));
},
withApiAuthRequired() {
throw new Error(serverSideOnly('withApiAuthRequired'));
},
handleLogin() {
throw new Error(serverSideOnly('handleLogin'));
},
handleLogout() {
throw new Error(serverSideOnly('handleLogout'));
},
handleCallback() {
throw new Error(serverSideOnly('handleCallback'));
},
handleProfile() {
throw new Error(serverSideOnly('handleProfile'));
},
handleAuth() {
throw new Error(serverSideOnly('handleAuth'));
},
withPageAuthRequired() {
throw new Error(serverSideOnly('withPageAuthRequired'));
},
getServerSidePropsWrapper() {
throw new Error(serverSideOnly('getServerSidePropsWrapper'));
}
};
export const initAuth0: InitAuth0 = () => instance;
export const getSession: GetSession = (...args) => instance.getSession(...args);
export const getAccessToken: GetAccessToken = (...args) => instance.getAccessToken(...args);
export const withApiAuthRequired: WithApiAuthRequired = (...args) => instance.withApiAuthRequired(...args);
export const handleLogin: HandleLogin = (...args) => instance.handleLogin(...args);
export const handleLogout: HandleLogout = (...args) => instance.handleLogout(...args);
export const handleCallback: HandleCallback = (...args) => instance.handleCallback(...args);
export const handleProfile: HandleProfile = (...args) => instance.handleProfile(...args);
export const handleAuth: HandleAuth = (...args) => instance.handleAuth(...args);