首页 > 解决方案 > 重定向链接不正确(在 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'作为方案是否正确?

标签: react-nativeexpospotify

解决方案


推荐阅读