1 個回答
- 最新
- 最多得票
- 最多評論
0
You can not only set the Amplify configuration initially but also adjust per use.
So you can call Amplify.configure
passing a patch
to the settings sometimes.
Below you see an example where I used USER_SRP_AUTH
and used a fallback to USER_PASSWORD_AUTH
. (This is because when migrating users using Cognito Migration Triggers passwords need to be cleartext to be rehashed). But you can switch to custom auth.
The code is from a React project:
import Amplify from '@aws-amplify/core'; import Auth from '@aws-amplify/auth'; ... handleSubmitLogin = async values => { const { login: { email, password } } = values; const { location: { search } } = this.props; try { let failed = false; try { Amplify.configure({ Auth: { authenticationFlowType: 'USER_SRP_AUTH' } }); await Auth.signIn(email.trim().toLowerCase(), password); } catch(error) { console.log(error); failed = true; } if (failed) { Amplify.configure({ Auth: { authenticationFlowType: 'USER_PASSWORD_AUTH' } }); await Auth.signIn(email.trim().toLowerCase(), password); } const params = queryString.parse((search || '?').substr(1)); await this.props.handleLogin(params.ReturnUrl || '/profile/'); } catch (e) { this.setState({ loginError: e.message }); } };
已回答 2 年前
相關內容
- AWS 官方已更新 2 年前
Although this seems possible in react js, I'm not quite sure how to translate this to android(java/kotlin) and ios(swift). Amplify JS seems to have much more in terms of documentation compared to the android and iOS counterparts
https://github.com/aws-amplify/aws-sdk-android/blob/5dfea2ce4e1616876b74c148fe12a8da023799e5/aws-android-sdk-mobile-client/src/test/java/com/amazonaws/mobile/client/AWSMobileClientAuthFlowSettingTest.java#L198
Here you see a test file that changes the flowtype by calling mobileClient.initialize again