Next.js Discord

Discord Forum

Calling Spring Boot endpoint after succesful NextAuth sign in (OAuth2).

Unanswered
Chilean jack mackerel posted this in #help-forum
Open in Discord
Chilean jack mackerelOP
Hello,

This is my use case and I am really stuck because I can't find any working solution anywhere and the docs aren't helpful either.

I managed to add NextAuth v4 with OAuth2 (google provider) in my NextJS app that I am using as the frontend. It works fine.

What I want to do now, is to somehow send a request to an endpoint exposed by my Spring Boot backend (let's call it http://localhost:8080/authenticate) after the user succesfully Signs In in my NextJS app, sending the token to it where the user email will be extracted and it will check if the user already exists in the database and if not, create it.

I made some research and found that there are some possible callbacks I could use: signIn(), session() and jwt().

I am attaching a screenshoot of my current [...nextauth].js file. It doesn't seem to work this way.

Anyone faced a similar scenario or use case? Am I mixing things up?

Thanks

6 Replies

Giant panda
The syntax is slightly wrong since session gets a single object as a parameter.
Also you never specified in what way it "doesn't work"
Chilean jack mackerelOP
@Giant panda It's the fact that I believe that you cannot perform any kind of request in a callback or event method
I have tried many different things. For example,
If I do this:
I get this:
But if I do this, the login is succesful. But I just want to be able to sent to the backend either the JWT token or the email that just logged in.