admin管理员组文章数量:1406937
I set up Auth0 in React Native (using Expo iOS app Xcode simulator). When "login" is invoked, it doesn't run "authorize()". It's not taking me to the Auth0 login page. For my callback URL in Auth0, I set it to localhost:19000 (which is the same as my expo-client).
import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Button, Text, View } from 'react-native';
import {useAuth0, Auth0Provider} from 'react-native-auth0';
const Home = () => {
const {authorize, clearSession, user} = useAuth0();
const login = async () => {
try {
await authorize();
} catch (err) {
console.log(err);
}
}
const onLogout = async () => {
try {
await clearSession();
} catch (err) {
console.log('log out canceled');
}
}
return (
<View style={styles.container}>
{!user && <Button onPress={login} title="Log in" />}
{user && <Text>Logged in as {user.name}</Text>}
</View>
)
}
const App = () => {
return (
<Auth0Provider domain={"ihavemydomainhere} clientId={"ihavemyclientidhere"}>
<Home />
</Auth0Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
I set up Auth0 in React Native (using Expo iOS app Xcode simulator). When "login" is invoked, it doesn't run "authorize()". It's not taking me to the Auth0 login page. For my callback URL in Auth0, I set it to localhost:19000 (which is the same as my expo-client).
import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Button, Text, View } from 'react-native';
import {useAuth0, Auth0Provider} from 'react-native-auth0';
const Home = () => {
const {authorize, clearSession, user} = useAuth0();
const login = async () => {
try {
await authorize();
} catch (err) {
console.log(err);
}
}
const onLogout = async () => {
try {
await clearSession();
} catch (err) {
console.log('log out canceled');
}
}
return (
<View style={styles.container}>
{!user && <Button onPress={login} title="Log in" />}
{user && <Text>Logged in as {user.name}</Text>}
</View>
)
}
const App = () => {
return (
<Auth0Provider domain={"ihavemydomainhere} clientId={"ihavemyclientidhere"}>
<Home />
</Auth0Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
Share
Improve this question
edited Jan 11, 2023 at 23:03
Phil
165k25 gold badges262 silver badges267 bronze badges
asked Jan 11, 2023 at 22:58
kirasam72kirasam72
1652 silver badges10 bronze badges
4
-
It seems impossible for
login()
to not runauthorize()
. What makes you think that is what's happening? – Phil Commented Jan 11, 2023 at 23:06 - When I open my Expo Go App and press on “login”, it doesn’t do anything. – kirasam72 Commented Jan 11, 2023 at 23:24
-
Does it log anything at all? Perhaps you could add some debugging logs, eg
console.log("Starting login")
– Phil Commented Jan 11, 2023 at 23:25 - Did you manage to fix it? I think running eas build and running the development build should work. I'm asking because when it works, even after authorize(), it redirects but { user } always just remains null – username-yj Commented Apr 10, 2023 at 11:21
1 Answer
Reset to default 5react-native-auth0
use native code which is not patible with Expo Go. That’s why is not doing anything. Try building a dev build, that should work.
Source: https://auth0./docs/quickstart/native/react-native-expo/interactive (the WARN message states “ This SDK is not patible with "Expo Go" app. It is patible only with Custom Dev Client and EAS builds.”)
Hope that helps
本文标签: javascriptSetting up Auth0 in React NativeExpoStack Overflow
版权声明:本文标题:javascript - Setting up Auth0 in React NativeExpo - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744974310a2635424.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论