-
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 #52658 from Expensify/nikki-saml-use-post
Use POST for SAML login
- Loading branch information
Showing
6 changed files
with
117 additions
and
22 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,21 +1,42 @@ | ||
import React, {useEffect} from 'react'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {useOnyx} 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({credentials}: SAMLSignInPageProps) { | ||
function SAMLSignInPage() { | ||
const {translate} = useLocalize(); | ||
const [credentials] = useOnyx(ONYXKEYS.CREDENTIALS); | ||
|
||
useEffect(() => { | ||
window.location.replace(`${CONFIG.EXPENSIFY.SAML_URL}?email=${credentials?.login}&referer=${CONFIG.EXPENSIFY.EXPENSIFY_CASH_REFERER}`); | ||
}, [credentials?.login]); | ||
// 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]); | ||
|
||
return <SAMLLoadingIndicator />; | ||
} | ||
|
||
SAMLSignInPage.displayName = 'SAMLSignInPage'; | ||
|
||
export default withOnyx<SAMLSignInPageProps, SAMLSignInPageOnyxProps>({ | ||
account: {key: ONYXKEYS.ACCOUNT}, | ||
credentials: {key: ONYXKEYS.CREDENTIALS}, | ||
})(SAMLSignInPage); | ||
export default SAMLSignInPage; |