react-native - 重定向链接不正确(在 expo 应用程序中发现身份验证)
问题描述
问题是构建的应用程序无法连接到 Spotify。但它在开发模式下工作。这是上下文:我们已经对本地 expo 应用程序做出反应,试图通过 expo-auth-session 中的 useAuthRequest 连接到 spotify(在后台使用链接)。登录-container.js:
import SignIn from './sign-in-component.js';
import { connect } from 'react-redux';
import {compose} from "ramda";
import React, {useEffect} from 'react';
import {isLogged} from "../../features/user-authentication/user-authentication-reducer";
import {signIn} from "../../features/user-authentication/user-authentication-saga";
import withGradient from "../../HOCs/with-gradient/with-gradient";
import {makeRedirectUri, useAuthRequest} from "expo-auth-session";
const mapStateToProps = state => ({
isLogged: isLogged(state),
});
const redirectUrl = makeRedirectUri();
const clientId = '***';
const discovery = {
authorizationEndpoint: 'https://accounts.spotify.com/authorize',
tokenEndpoint: 'https://accounts.spotify.com/api/token',
};
export default compose(
connect(mapStateToProps, {signIn}),
withGradient,
)(({ isLogged, signIn, navigation }) => {
const [request, response, promptAsync] = useAuthRequest(
{
clientId: clientId,
scopes: ['user-read-email', 'playlist-modify-public'],
usePKCE: false,
redirectUri: redirectUrl,
},
discovery
);
useEffect(() => {
if (response?.type === 'success') {
const { code } = response.params;
signIn(code);
}
}, [response]);
const handlePressSpotifyButton = () => {
promptAsync().then(() => {
navigation.navigate('Onboarding')
});
};
return <SignIn isLogged={isLogged} onPressSpotifyButton={handlePressSpotifyButton}/>;
});
并在开发模式下启动项目时收到警告(纱线启动):
链接需要项目的 Expo 配置(app.config.js 或 app.json)中用于生产应用程序的构建时设置方案,如果它留空,您的应用程序可能会崩溃。该方案不适用于 Expo 客户端中的开发,但您应该在开始使用 Linking 后立即添加它,以避免创建损坏的构建。了解更多: https ://docs.expo.io/versions/latest/workflow/linking/
没有方案,它不会通过 expo publish/expo build 添加“exp”作为 app.json 配置的方案
"scheme": "exp"
发布后出现错误incorrect redirect link
应用程序中的重定向链接:
- 本地开始:exp://192.168.0.159:19000(工作)
- 发布:exp://exp.host/@expo-user-name/my-app(不正确)
重定向链接不仅在开发模式下应该如何工作?添加'exp'作为方案是否正确?
解决方案
推荐阅读
- reactjs - 需要帮忙!React 组件导出不起作用>_<
- arrays - 从数组中删除多个项目 - Redux State
- json - 当响应是对象数组时如何在颤动中解析JSON
- powershell - 通过带有批处理文件的PowerShell发送带有附件的电子邮件
- mongodb - Spark-提交配置:jars,packages
- android - 我创建了一个自适应布局,它工作正常,但我知道它不是很好,所以,需要一个更好的解决方案
- r - 如何将生成的热图导出为 R 中的 8 位/16 位 tiff 图像,以便在 ImageJ/Fiji 中进行分析?
- websocket - Micronaut Websocket 连接每 5 分钟超时一次
- python - node-red 中的 Python 函数 - Windows 系统上的问题
- rust - 如何在通过 C++ 创建的 Rust 代码中保存 Rust 对象?