admin管理员组文章数量:1124074
I'm encountering a 409 Conflict error when trying to redirect a user to the dashboard after a successful login in my Laravel + InertiaJS application. I've tried several approaches, but the issue persists, and I'm looking for a clear solution to resolve this problem.
Setup Details: Backend (Laravel):
Laravel 11 InertiaJS PHP 8.4 Frontend (Vue): Using @inertiajs/inertia Vue 3
Front end:
onSubmit() {
this.$refs.login.validate((valid) => {
if (valid) {
this.form.post(route('login'), {
onFinish: () => {
this.form.reset('password'),
this.loading = false;
},
onError: (errors) => {
if (errors.message) {
this.hasError = true
this.error = errors.message;
}
}
});
}
});
},
From laravel:
public function login(Request $request) { $validEmail = '[email protected]'; $validPassword = 'password';
// Verify credentials
if ($request->email === $validEmail && $request->password === $validPassword) {
$request->session()->regenerate();
if ($request->header('X-Inertia')) {
return Inertia::location(route('dashboard'));
}
return redirect()->route('dashboard');
}
return Inertia::render('Auth/Login', [
'errors' => ['message' => 'Invalid credentials.'],
]);
}
Question: What is the best way to handle this scenario in InertiaJS to ensure proper redirection to /dashboard after login? Am I missing something in the backend logic or the frontend configuration?
Thank you in advance for your help!
What I've Tried: Using Inertia::location(route('dashboard')). Returning a redirect()->route('dashboard'). Returning JSON responses and handling redirection explicitly on the frontend using this.$inertia.visit('/dashboard'). Checked for correct headers like X-Inertia, X-Inertia-Version, and X-XSRF-TOKEN.
本文标签: phpHow to Resolve 409 Conflict with InertiaJS on Login Redirect in LaravelStack Overflow
版权声明:本文标题:php - How to Resolve 409 Conflict with InertiaJS on Login Redirect in Laravel? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736616093a1945471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论