admin管理员组文章数量:1391999
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())
本文标签: inertiajsshared user in adonis inertia config is not coming into vue propsStack Overflow
版权声明:本文标题:inertiajs - shared user in adonis inertia config is not coming into vue props - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744657835a2618072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论