我正在尝试使用 Expo 为多个不同的平台构建一个应用程序,包括桌面 - 使用 Electron。现在我在继续记录过程直到结束时遇到问题。
我知道 Electron 使用 Expo React Native Web Features,但我不明白如何在重定向后继续记录过程。
这是我尝试过的:
const useProxy = Platform.OS !== 'web';
export function AuthScreen() {
const {nextState} = useAuth();
const discovery = AuthSession.useAutoDiscovery('https://my-open-id.url');
const redirectUri = AuthSession.makeRedirectUri({
useProxy,
});
// Create and load an auth request
const [request, , promptAsync] = AuthSession.useAuthRequest(
{
clientId: 'client-id',
clientSecret: 'client-secret',
redirectUri,
scopes: ['openid', 'profile', 'email', 'offline_access'],
},
discovery
);
const login = useCallback(async () => {
const result = await promptAsync({useProxy});
console.log({result});
if (!result) {
return;
}
switch (result.type) {
case "cancel":
case "dismiss":
return;
case "error":
return;
case "locked":
return;
case "success":
const token = result.authentication;
nextState(token);
return;
}
}, [promptAsync]);
if (Platform.OS !== 'web') {
useEffect(() => {
WebBrowser.warmUpAsync();
return () => {
WebBrowser.coolDownAsync();
}
}, []);
}
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text>Auth Screen</Text>
<Button title="Login!" disabled={!request} onPress={login}/>
</View>
);
}
每当我点击Login
按钮时,我都会被重定向到我的 OAuth2 服务器并且我可以登录。之后,我应该被重定向到我的应用程序,但没有。
在登录过程之后,新窗口仍然存在,并且该应用程序的另一个实例继续存在。
我也在寻找电子功能,以了解如何充分破解它,以便拥有完整的工作流程,但我仍然不知道如何从代码的本机反应部分访问电子的主要过程。
任何帮助,将不胜感激。