Out of the box, the adonis inertia.js config file had this section of code:
sharedData: {
user: (ctx) => ctx.inertia.always(() => ctx.auth.user),
},
But in my vue components, when I add user to defineProps it is undefined.
I am using Ally to authenticate with microsoft and then creating a user to login with. Here is my controller that does that:
import type { HttpContext } from '@adonisjs/core/http'
import User from '#models/user'
export default class MicrosoftLoginsController {
public async redirect({ally}: HttpContext) {
return ally.use('microsoft').redirect()
}
public async handleCallback ({ally, auth, response}: HttpContext) {
const ms = ally.use('microsoft')
if (ms.accessDenied()) {
return 'You have cancelled the login process'
}
if (ms.stateMisMatch()) {
return 'We are unable to verify the request. Please try again'
}
if (ms.hasError()) {
return ms.getError()
}
const user = await ms.user()
const findUser = {
email: user.original.mail
}
const userDetails = {
fullName: user.original.displayName,
email: user.original.mail,
providerId: user.original.id,
provider: 'microsoft'
}
const newUser = await User.firstOrCreate(findUser, userDetails)
await auth.use('web').login(newUser)
return response.redirect('/')
}
}
What am I missing? The documentation on the AdonisJS site doesn't go into much detail.
Out of the box, the adonis inertia.js config file had this section of code:
sharedData: {
user: (ctx) => ctx.inertia.always(() => ctx.auth.user),
},
But in my vue components, when I add user to defineProps it is undefined.
I am using Ally to authenticate with microsoft and then creating a user to login with. Here is my controller that does that:
import type { HttpContext } from '@adonisjs/core/http'
import User from '#models/user'
export default class MicrosoftLoginsController {
public async redirect({ally}: HttpContext) {
return ally.use('microsoft').redirect()
}
public async handleCallback ({ally, auth, response}: HttpContext) {
const ms = ally.use('microsoft')
if (ms.accessDenied()) {
return 'You have cancelled the login process'
}
if (ms.stateMisMatch()) {
return 'We are unable to verify the request. Please try again'
}
if (ms.hasError()) {
return ms.getError()
}
const user = await ms.user()
const findUser = {
email: user.original.mail
}
const userDetails = {
fullName: user.original.displayName,
email: user.original.mail,
providerId: user.original.id,
provider: 'microsoft'
}
const newUser = await User.firstOrCreate(findUser, userDetails)
await auth.use('web').login(newUser)
return response.redirect('/')
}
}
What am I missing? The documentation on the AdonisJS site doesn't go into much detail.
Share Improve this question edited Mar 14 at 17:29 RyanJMP asked Mar 14 at 12:03 RyanJMPRyanJMP 134 bronze badges 1- I have disabled ssr in my project. Would that make a difference? – RyanJMP Commented Mar 14 at 12:14
1 Answer
Reset to default 0Found the answer on another forum. I was not using the auth middleware. To fix it, in my routes file all I had to do was add:
import { middleware } from '#start/kernel'
router.get('/', [HomeController, 'index']).use(middleware.auth())