Back

[SOLVED] OAuth2 Spotify

  • 0
  • Accounts
  • Web
Kenny
2 Jun, 2023, 13:21

I will say the spotify auth works if there is an existing account in the users with an email that matches what spotify has. It's not working when there is no matching user, but in the docs it reads as though it would create a user with the email provided by spotify.

TL;DR
Issue: OAuth2 Spotify not creating new user when there is no matching user in the database. Solution: - Delete old account and try again. - Add `user-read-email` scope to the code. - Check the OAuth2 code in the JS. - Run `curl https://api.spotify.com/v1/me` on the server to check for errors. - Check the logs using `docker logs appwrite` and `docker ps -a`. - Make sure the server IP is correctly configured in the Google Domains dashboard. - Share the whole error for further investigation.
Kenny
2 Jun, 2023, 13:23

In google domains dashboard I have an A record setup to point to the server IP given by DigitalOcean

Binyamin
2 Jun, 2023, 13:24

Interesting.. And you're correct it should create the new user. Can you share the whole error?

Kenny
2 Jun, 2023, 13:25
Binyamin
2 Jun, 2023, 13:25

Can you run these commands and share the results?

TypeScript
docker logs appwrite
docker ps -a
Kenny
2 Jun, 2023, 13:32

This is all I have from the timeframe I was getting this error

Kenny
2 Jun, 2023, 13:33
Kenny
2 Jun, 2023, 13:39

Sorry, ignore that top log. I forgot to account for the time different. Here is the correct logs

Kenny
2 Jun, 2023, 13:39

Error] Timestamp: 2023-06-02T02:01:12+00:00 [Error] Method: GET [Error] URL: /v1/account/sessions/oauth2/:provider/redirect [Error] Type: TypeError [Error] Message: Cannot assign null to property Appwrite\Auth\OAuth2\Spotify::$user of type array [Error] File: /usr/src/code/src/Appwrite/Auth/OAuth2/Spotify.php [Error] Line: 171

Binyamin
2 Jun, 2023, 13:48

Mmm this is really weird as the request to Spotify should return something, at least error JSON Can you run curl https://api.spotify.com/v1/me in your server? and show the results?

Kenny
2 Jun, 2023, 13:49
Binyamin
2 Jun, 2023, 13:50

So it's not blocked from your server

Kenny
2 Jun, 2023, 13:50

No, and like I had put above. I can login and authenticate via spotify if a user is preexisting in the db.

Kenny
2 Jun, 2023, 13:50

It's just won't create a new user via spotify auth

Binyamin
2 Jun, 2023, 13:51

That's right, because this endpoint https://api.spotify.com/v1/me is called three times and two of which only if the user doesn't exist

Kenny
2 Jun, 2023, 13:52

Ah okay

Binyamin
2 Jun, 2023, 13:55

can you share your OAuth2 code from the JS?

Kenny
2 Jun, 2023, 13:58

Lines 71 - 86

Binyamin
2 Jun, 2023, 14:01

Can you try to add this user-read-email scope? and try again?

Kenny
2 Jun, 2023, 14:01

Yea, it might take some time, but I will.

Kenny
2 Jun, 2023, 14:13

I deleted my old account and tried again and it seemed to have worked.

Binyamin
2 Jun, 2023, 14:19

πŸ‘

Kenny
2 Jun, 2023, 14:27

Thanks for all your help πŸ™‚ It's very much appreciated.

Drake
2 Jun, 2023, 17:28

[SOLVED] OAuth2 Spotify

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more