Auth not succesfull on subdomain route


#1

I have succesfully integrated two subdomains on my adonis app. nama.local and user.name.local. When I the user is logged in. I can successfully use the auth variable to access all the auth properties of the logged in user on name.local domain name but for the user.name.local domain name, all the auth properties return undefined. Plus the auth middleware returns invalid session error even when the user is logged in, on the same domain name. Any one that can help in solving this, I will appreciate. Thanks you


#2

@virk can you help with this. I want to use one session accross mutlple sub domains i.e auth should work in foo.local and user.foo.local. As things stand now, it is only working on foo.local


#3

You will have to set the domain inside config/session.js file under the cookie options.

cookie: {
  httpOnly: true,
  domain: 'foo.local'
}

#4

@virk thanks very much for your answer

cookie: {
httpOnly: true,
domain: ‘foo.local’,
sameSite: false,
path: ‘/’
},

it works for domain accounts.foo.local but not for foo.local. i.e session is not saved on the main domain which is foo.local but works for accounts.foo.local


#5

How about is I have multiple domain names, can use objects instead of string


#6

Can you share following.

  1. Is authentication done on accounts.foo.local or foo.local?
  2. The HTTP response header after user is logged in?

#7

auth is done foo.local then redirects to accounts.fool.local