I have a next js application using’@auth0/nextjs-auth0’ for login. The next js server side pages are protected by auth0Server.withPageAuthRequired() method, the auth0 server is instantiated using client id and secret using initAuth0 from nextjs-auth0 library.
The current application (app1) works on user name/password auth through a db connection.
Now we are including a button in the login page of app1, which will redirect user to another auth0 application (lets say app2).
After the user enters the credentials for app2 and gets authenticated, we wan redirect the user back to website, but since the nextjs auth0 instance is set to app1, the application not recognizing the session from app2 and its failing the auth.
The app1 and app2 are sharing same domain and same tenant , but they have connected to different data bases and the user ids are different for them. Is there a way to share the session between these two apps so that my next js app understands session from app2?
i’m aware of the auth0 session layer, but i do not know the exact steps on how to enable this to my applications, they use different data bases and they have different user ids.
Also lets we are doing account liking to app1 info after app2 login and combine identities does that help in recognizing the session?
Hi @sandhya.karanam,
Welcome to the Auth0 Community!
It sounds to me like you’re using two Auth0 Applications in a single NextJS project. I’d suggest making two different NextJS projects and using the app2 credentials for the second one. Then you can have the app1 redirect to the app2 much more easily and with no errors.
If you want the same users to be recognized in both applications they will need to use the same database. You’ll have to use the same connections for both applications.
If you have any questions feel free to reach out.
Have a good one,
Vlad
Thanks for the quick response Vlad.
follow up to this,
Two applications can’t share the session through auth0 session layer even though they are in the same tenant, unless they are using same user id and data base connection. Is my understanding correct here?
Also lets say if the users under these two different applications are linked through identities, will that give us a possibility for session sharing? example record where the user accounts are linked.
{
"created_at": "2022-11-28T09:27:33.573Z",
"email": “user@testorg.com",
"email_verified": true,
"identities": [
{
"connection": “app1-db”,
"provider": "auth0",
"user_id": “app1_id”,
"isSocial": false
},
{
"profileData": {
"email": “user123@abc.com"
},
"connection": “app”2_db,
"provider": "auth0",
"user_id": “a”pp2_id,
"isSocial": false
}
],
"name": "user@testorg.com",
"nickname": “user”,
"picture": "https://s.gravatar.com.png",
"updated_at": "2025-04-07T19:20:31.569Z",
"user_id": "auth0|app1_id”,
"last_ip": "2601:646:9d00:1570:144d:b828:d856:ce91",
"last_login": "2025-04-07T19:20:31.553Z",
"logins_count": 4,
"blocked_for": [],
"guardian_authenticators": [],
"passkeys": []
}
And last question is when you mentioned i can use two separate applications, how does the redirection work? when my first next js app1 is expecting auth0 app1 session( this is where my current project is running), even though i redirect to another next js app with auth0 app2, how can i get back to my app1 and get authenticated (this is needed since app1 is my main project)? do you have any examples or documentation around this.
Thanks,
Sandhya
Auth0 supports SSO by default, which allows your users to log in to one of your applications and have their session used for other apps in your tenant.
The easiest and most straightforward way of maintaining the session would be if both applications used the same database. That would let users jump into both apps with the same account, just like how Microsoft lets you use the same Microsoft account to access apps such as the Office suite, the To-Do app, and the Xbox platform. Having both apps use different connections and linking accounts will still create a single user with two different ways of signing in, which only adds more unnecessary complexity.
And for your last question, I want to make sure I understood, do you want to use your app2 as a social connection in the same way you would use Google or GitHub?
And then use the app2’s account to sign in into app1?
Or do you want your app1 and app2 to work in the same ecosystem and use both with the same account, similar to the Google ecosystem?
Apologies if I misunderstood your architecture.
Have a good one,
Vlad