我对react-native
和firebase
极为陌生,我正在尝试设置Passwordless Auth
。
我尚未编写的代码:
import React, {Component} from 'react';
import {View, TextInput, Button} from 'react-native';
import auth from '@react-native-firebase/auth';
import AsyncStorage from '@react-native-community/async-storage';
class App extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
emailSent: false,
};
}
setEmail = async email => {
try {
await AsyncStorage.setItem('emailLink', `${email}`);
} catch (e) {
// save error
}
console.log('Email is set');
};
getEmail = async () => {
try {
var value = await AsyncStorage.getItem('emailLink');
} catch (e) {
// read error
}
console.log('Got email: ', value);
};
sendEmailLink() {
var actionCodeSettings = {
// The URL to redirect to for sign-in completion. This is also the deep
// link for mobile redirects. The domain (www.example.com) for this URL
// must be whitelisted in the Firebase Console.
url: 'https://passless.page.link/85EH',
iOS: {
bundleId: 'org.reactjs.native.example.passless',
},
android: {
packageName: 'com.passless_auth',
installApp: true,
minimumVersion: '12',
},
// This must be true.
handleCodeInApp: true,
};
auth()
.sendSignInLinkToEmail(`${this.state.email}`, actionCodeSettings)
.then(() => console.log('email is sent'))
.then(() => this.setEmail(`${this.state.email}`))
.catch(err => console.log('error sending email', err));
}
render() {
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<TextInput
placeholder="email"
onChangeText={email => this.setState({email: email})}
/>
<Button title="SignUp/LogIn" onPress={() => this.sendEmailLink()} />
</View>
);
}
}
export default App;
我已成功接收电子邮件,但链接不起作用。
电子邮件中的链接在浏览器而不是应用程序中打开。我该如何解决?
我想我已经在控制台中正确设置了链接,但是我不确定我的代码。
我该如何进一步发展? 帮助将不胜感激。
我正在使用react-native-firebase v6
答案 0 :(得分:1)
将重定向URL从默认的URL更改为未在GCP上向您的项目注册的其他重定向URL时,会发生这种情况。
确保在GCP oAuth同意的Firebase项目的凭据部分中,将重定向URL列入白名单。
https://console.cloud.google.com/apis/credentials/consent
确保在那里已将您的重定向URL列入白名单。
我希望这会有所帮助。让我知道您是否遇到问题。