Typescript:尝试通过 Spotify API 验证登录时出错/长时间加载

问题描述 投票:0回答:0

我正在尝试构建具有一些附加功能的 Spotify 模拟器应用程序。

到目前为止,我已经克隆了以下 github 项目: https://reactjsexample.com/your-music-with-spotify-api-with-react-native-app/

并更改“use-login.ts”以包含我自己的 clientId 和 redirectUrl:

import {useContext} from 'react';
import {authorize} from 'react-native-app-auth';
import {MyContext} from '../context/context';
import {Types} from '../types/reducer-type';

const authConfig = {
  clientId: '07e1ed89337c47d9a2cb457bf3eb2b4b',
  // optional client secret
  // clientSecret: 'client secret',
  redirectUrl: 'http://localhost:3000/auth/callback',
  scopes: ['playlist-modify-public', 'playlist-modify-private'],
  serviceConfiguration: {
    authorizationEndpoint: 'https://accounts.spotify.com/authorize',
    tokenEndpoint: 'https://accounts.spotify.com/api/token',
  },
};

export default function useLogin() {
  // const {token, setToken} = useContext(AuthContext);
  const {state, dispatch} = useContext(MyContext);

  const authLogin = async () => {
    try {
      const result = await authorize(authConfig);

      // setToken(result.accessToken);
      dispatch({
        type: Types.Auth,
        payload: {
          token: result.accessToken,
        },
      });
    } catch (e) {
      console.log(e);
    }
  };

  return {
    state,
    authLogin,
  };
}

但是,在按下“同意”以授予该应用使用我的 Spotify 帐户的权限后, 右上角的'reload-page'符号一直闪烁,似乎陷入了无休止的重新加载循环。

到目前为止,我已经尝试重建应用程序,重新启动服务器并更改重定向 url(但这会导致另一个错误)

然而,无尽的加载仍在继续。

关于如何解决这个问题有什么建议吗? 非常感谢所有帮助!

spotify spotify-app
© www.soinside.com 2019 - 2024. All rights reserved.