Im trying to use the api routes feature from nextjs 14 to use user auth from spotify api
Answered
Fire ant posted this in #help-forum
Fire antOP
I am fairly new to Next so my knowledge is fairly limited when it comes to next, but like i mentioned im trying to make the user auth work for Spotify api, currently inside the app folder i have an api folder which contains a callback folder and a login folder both have route.js files I would really appriciate the help as ive been trying to figure out the issue all day, and watching dozons of videos. I have attached both the routes for the login and redirect login, the main idea was that when i go into /api/login spotify asks me to autherize then redirects me to the page redirec page, but that does not happen when i go to login it immedietly send me to redirected and shows me the page attached ( client id and secret are only hidden for privacy)
13 Replies
Fire antOP
Any chance someone could help with this please?
Pollock
api/callback endpoint exports
POST handler, but you're accessing it via GET, that's why you get 405 error@Pollock api/callback endpoint exports `POST` handler, but you're accessing it via `GET`, that's why you get 405 error
Fire antOP
So I should make both the handler functions GET I shouldn’t make one GET and one POST?
Pollock
if the spotify is making get request, then yes
@Pollock if the spotify is making get request, then yes
Fire antOP
so now i see a json file with only my current stuff im storing like code, url form etc, but the docs say ii should be getting this object
Pollock
huh?
you'll get those when calling the token endpoint
spotify sends you
code to the callback and you exchange the code for the access tokenthis is more oauth thing than next.js thing. you can also use next-auth instead of implementing the login on your own
@Pollock spotify sends you `code` to the callback and you exchange the `code` for the `access token`
Fire antOP
ohh i see i just need to add method : "POST" to the authoptions basically for hte callback, makes sense
@Pollock this is more oauth thing than next.js thing. you can also use next-auth instead of implementing the login on your own
Fire antOP
does it use the sopotify api if i use nextauth? because i would need the token and those stuff
Pollock
no idea, check their docs
Answer