@@ -21,11 +21,13 @@ import {
2121 ThirdPartyAuthType ,
2222 ThirdPartyConfigType ,
2323} from "constants/authConstants" ;
24+ import history from "util/history" ;
2425
2526export const AuthContext = createContext < {
2627 systemConfig ?: SystemConfig ;
2728 inviteInfo ?: AuthInviteInfo ;
2829 thirdPartyAuthError ?: boolean ;
30+ fetchUserAfterAuthSuccess ?: ( ) => void ;
2931} > ( undefined as any ) ;
3032
3133export const getSafeAuthRedirectURL = ( redirectUrl : string | null ) => {
@@ -39,15 +41,21 @@ export const getSafeAuthRedirectURL = (redirectUrl: string | null) => {
3941export function useAuthSubmit (
4042 requestFunc : ( ) => AxiosPromise < ApiResponse > ,
4143 infoCompleteCheck : boolean ,
42- redirectUrl : string | null
44+ redirectUrl : string | null ,
45+ onAuthSuccess ?: ( ) => void ,
4346) {
4447 const [ loading , setLoading ] = useState ( false ) ;
4548 return {
4649 loading : loading ,
4750 onSubmit : ( ) => {
4851 setLoading ( true ) ;
4952 requestFunc ( )
50- . then ( ( resp ) => authRespValidate ( resp , infoCompleteCheck , redirectUrl ) )
53+ . then ( ( resp ) => authRespValidate (
54+ resp ,
55+ infoCompleteCheck ,
56+ redirectUrl ,
57+ onAuthSuccess ,
58+ ) )
5159 . catch ( ( e ) => {
5260 messageInstance . error ( e . message ) ;
5361 } )
@@ -66,7 +74,8 @@ export function useAuthSubmit(
6674export function authRespValidate (
6775 resp : AxiosResponse < ApiResponse > ,
6876 infoCompleteCheck : boolean ,
69- redirectUrl : string | null
77+ redirectUrl : string | null ,
78+ onAuthSuccess ?: ( ) => void
7079) {
7180 let replaceUrl = redirectUrl || BASE_URL ;
7281 if ( infoCompleteCheck ) {
@@ -76,7 +85,8 @@ export function authRespValidate(
7685 : USER_INFO_COMPLETION ;
7786 }
7887 if ( doValidResponse ( resp ) ) {
79- window . location . replace ( replaceUrl ) ;
88+ onAuthSuccess ?.( ) ;
89+ history . replace ( replaceUrl ) ;
8090 } else if (
8191 resp . data . code === SERVER_ERROR_CODES . EXCEED_MAX_USER_ORG_COUNT ||
8292 resp . data . code === SERVER_ERROR_CODES . ALREADY_IN_ORGANIZATION
0 commit comments