@jsb188/auth-web 1.1.3 → 1.1.10
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/package.json +14 -7
- package/src/hooks/use-oauth.tsx +255 -52
- package/src/main.ts +8 -1
- package/src/modules/AssignRequiredAuth.tsx +228 -0
- package/src/modules/AuthFormUI.tsx +45 -0
- package/src/modules/AuthForms-SSO.tsx +187 -0
- package/src/modules/AuthForms.tsx +712 -0
- package/src/modules/AuthGate.tsx +64 -20
- package/src/modules/InlineAuthForm.tsx +148 -0
- package/src/modules/ManagedSessions.tsx +109 -0
- package/src/modules/OtherAuthButtons.tsx +114 -0
- package/src/modules/_helpers.ts +125 -0
- package/src/modules/schemas.ts +116 -100
- package/src/schemas/account.ts +162 -0
- package/src/schemas/address.ts +165 -0
- package/src/schemas/index.ts +2 -0
- package/src/ui/ManagedSessionUI.tsx +89 -0
- package/src/modules/AuthForm.tsx +0 -638
- package/src/modules/ContinueWithApple.tsx +0 -105
- package/src/modules/OAuthButtons.tsx +0 -48
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
-
import { getTimeBasedUnique } from '@jsb188/app/utils/string';
|
|
3
|
-
import { getENVVariable } from '@jsb188/app';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Types
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
interface AppleLoginProps {
|
|
10
|
-
scriptLoaded: boolean;
|
|
11
|
-
scope?: string;
|
|
12
|
-
onSuccess?: (res: any) => void;
|
|
13
|
-
onError?: (err: any) => void;
|
|
14
|
-
onNonOAuthError?: (err: any) => void;
|
|
15
|
-
overrideScope?: boolean;
|
|
16
|
-
state?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Apple OAuth login
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
function useAppleLogin(p: AppleLoginProps) {
|
|
24
|
-
const {
|
|
25
|
-
scriptLoaded,
|
|
26
|
-
scope = '',
|
|
27
|
-
onSuccess,
|
|
28
|
-
onError,
|
|
29
|
-
onNonOAuthError,
|
|
30
|
-
overrideScope,
|
|
31
|
-
state,
|
|
32
|
-
...props
|
|
33
|
-
} = p;
|
|
34
|
-
|
|
35
|
-
const clientRef = useRef<any>();
|
|
36
|
-
|
|
37
|
-
const onSuccessRef = useRef(onSuccess);
|
|
38
|
-
onSuccessRef.current = onSuccess;
|
|
39
|
-
|
|
40
|
-
const onErrorRef = useRef(onError);
|
|
41
|
-
onErrorRef.current = onError;
|
|
42
|
-
|
|
43
|
-
const onNonOAuthErrorRef = useRef(onNonOAuthError);
|
|
44
|
-
onNonOAuthErrorRef.current = onNonOAuthError;
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (scriptLoaded) {
|
|
48
|
-
const client = globalThis.google?.accounts?.oauth2.initTokenClient({
|
|
49
|
-
client_id: getENVVariable('GOOGLE_OAUTH'),
|
|
50
|
-
scope: overrideScope ? scope : `openid profile email ${scope}`,
|
|
51
|
-
callback: (response) => {
|
|
52
|
-
if (response.error) {
|
|
53
|
-
return onErrorRef.current?.(response);
|
|
54
|
-
}
|
|
55
|
-
onSuccessRef.current?.(response as any);
|
|
56
|
-
},
|
|
57
|
-
error_callback: (nonOAuthError) => {
|
|
58
|
-
onNonOAuthErrorRef.current?.(nonOAuthError);
|
|
59
|
-
},
|
|
60
|
-
state,
|
|
61
|
-
...props,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
clientRef.current = client;
|
|
65
|
-
}
|
|
66
|
-
}, [scriptLoaded, scope, state]);
|
|
67
|
-
|
|
68
|
-
return useCallback((overrideConfig?: object) => {
|
|
69
|
-
clientRef.current?.requestAccessToken(overrideConfig);
|
|
70
|
-
}, []);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Web sign in with Apple
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
function useContinueWithApple(Cmp) {
|
|
78
|
-
function WebSignInWithApple(p) {
|
|
79
|
-
|
|
80
|
-
const onInitiateAppleSignIn = () => {
|
|
81
|
-
globalThis.location.href = (
|
|
82
|
-
'https://appleid.apple.com/auth/authorize' +
|
|
83
|
-
'?client_id=' + getENVVariable('APPLE_APP_ID') +
|
|
84
|
-
'&redirect_uri=' + encodeURIComponent('https://bigplanet.ai/auth/apple') +
|
|
85
|
-
'&response_type=' + encodeURIComponent('code id_token') +
|
|
86
|
-
'&state=' + getTimeBasedUnique() +
|
|
87
|
-
'&scope=' + encodeURIComponent('email name') +
|
|
88
|
-
'&response_mode=form_post'
|
|
89
|
-
// '&frame_id'=36394414-f7d7-4021-8f98-64e7be74e283&m=11&v=1.5.5'
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
return (
|
|
94
|
-
<Cmp
|
|
95
|
-
{...p}
|
|
96
|
-
onInitiateAppleSignIn={onInitiateAppleSignIn}
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// return composeSignInWithApple(WebSignInWithApple);
|
|
102
|
-
return WebSignInWithApple;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default useContinueWithApple = useContinueWithApple;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n';
|
|
2
|
-
import { SpecialIcon } from '@jsb188/react-web/icons';
|
|
3
|
-
import { FullWidthButton } from '@jsb188/react-web/ui/Button';
|
|
4
|
-
import { useContinueWithGoogle, useContinueWithApple } from '../hooks/use-oauth';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Google OAuth button
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export const ContinueWithGoogle = (p: any) => {
|
|
11
|
-
const { onFinishSignIn } = p;
|
|
12
|
-
const { onInitiateGoogleSignIn, waitingForOAuth } = useContinueWithGoogle({
|
|
13
|
-
onFinishSignIn
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<FullWidthButton
|
|
18
|
-
loading={waitingForOAuth}
|
|
19
|
-
onClick={onInitiateGoogleSignIn}
|
|
20
|
-
preset='em'
|
|
21
|
-
className='mb_sm'
|
|
22
|
-
IconComponent={SpecialIcon}
|
|
23
|
-
iconName='google'
|
|
24
|
-
>
|
|
25
|
-
{i18n.t('auth.continue_with_google')}
|
|
26
|
-
</FullWidthButton>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Apple OAuth button
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
export const ContinueWithApple = (p: any) => {
|
|
35
|
-
const { onInitiateAppleSignIn } = useContinueWithApple();
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<FullWidthButton
|
|
39
|
-
onClick={onInitiateAppleSignIn}
|
|
40
|
-
preset='em'
|
|
41
|
-
className='mb_sm'
|
|
42
|
-
iconName='brand-apple-filled'
|
|
43
|
-
// iconName='heart'
|
|
44
|
-
>
|
|
45
|
-
{i18n.t('auth.continue_with_apple')}
|
|
46
|
-
</FullWidthButton>
|
|
47
|
-
);
|
|
48
|
-
};
|