-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55432 from Expensify/revert-52658-nikki-saml-use-…
…post Revert "Use POST for SAML login" (cherry picked from commit ecb1e51) (CP triggered by mountiny)
- Loading branch information
1 parent
517f585
commit b00cd6b
Showing
6 changed files
with
22 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,21 @@ | ||
import React, {useEffect} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import SAMLLoadingIndicator from '@components/SAMLLoadingIndicator'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import * as LoginUtils from '@libs/LoginUtils'; | ||
import CONFIG from '@src/CONFIG'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {SAMLSignInPageOnyxProps, SAMLSignInPageProps} from './types'; | ||
|
||
function SAMLSignInPage() { | ||
const {translate} = useLocalize(); | ||
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); | ||
|
||
function SAMLSignInPage({credentials}: SAMLSignInPageProps) { | ||
useEffect(() => { | ||
// If we don't have a valid login to pass here, direct the user back to a clean sign in state to try again | ||
if (!credentials?.login) { | ||
LoginUtils.handleSAMLLoginError(translate('common.error.email'), true); | ||
return; | ||
} | ||
|
||
const body = new FormData(); | ||
body.append('email', credentials.login); | ||
body.append('referer', CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER); | ||
|
||
LoginUtils.postSAMLLogin(body) | ||
.then((response) => { | ||
if (!response || !response.url) { | ||
LoginUtils.handleSAMLLoginError(translate('common.error.login'), false); | ||
return; | ||
} | ||
window.location.replace(response.url); | ||
}) | ||
.catch((error: Error) => { | ||
LoginUtils.handleSAMLLoginError(error.message ?? translate('common.error.login'), false); | ||
}); | ||
}, [credentials?.login, translate]); | ||
window.location.replace(`${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials?.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}`); | ||
}, [credentials?.login]); | ||
|
||
return <SAMLLoadingIndicator />; | ||
} | ||
|
||
SAMLSignInPage.displayName = 'SAMLSignInPage'; | ||
|
||
export default SAMLSignInPage; | ||
export default withOnyx<SAMLSignInPageProps, SAMLSignInPageOnyxProps>({ | ||
account: {key: ONYXKEYS.ACCOUNT}, | ||
credentials: {key: ONYXKEYS.CREDENTIALS}, | ||
})(SAMLSignInPage); |