I used to use adonuxt which worked nice but it's depreciated. So I am now trying to use nuxt.js separate with adonis backend. I am trying to make login system. These two projects run on two separate port in localhost. http://localhost:3000/
nuxt project and http://localhost:3333/
adonis project.
How can I get logged in user information in nuxtServerInit?
I am trying like this
async nuxtServerInit({ commit }, { $axios }) {
console.log('I am running as nuxt server init')
try {
// get the initial data
let { data } = await axios.get('http://localhost:3333/myuser')
commit('loginUser', data)
} catch (e) {
console.log('nuxt server error ', e.response)
}
},
and in my adonis.js I am trying
async getUser({request, response, params, auth}){
try {
const user = await auth.getUser()
return user
} catch (error) {
return 'not logged in'
}
}
The result is always not logged in
....
Any idea how to implement.....
UPDATE
I am using a very simple login system
async user({request, response, params, auth}){
try {
const user = await auth.loginViaId(34)
return user
} catch (error) {
return error
}
}
I got a very interesting result now. So if I login using my adonis project then the logged in user information becomes available in nuxt project but I cannot get the logged in user if I login using nuxt axios
UPDATE 2
So, session login works, but adonis cannot find user or loggedin user when axios is used.
UPDATE 3
we can get logged in user only using nuxtServerInit.. We can get the logged in user using axios.. :(