Support the ongoing development of Laravel.io →
Laravel Session Vue.js
0

It seems that the issue you're facing is related to using Inertia.js with Laravel. In Inertia.js, you cannot return a traditional redirect response from your controller. Instead, you should use Inertia's native methods to handle redirection.

Update your authenticateAgency method to return an Inertia response:

use Inertia\Inertia;

public function authenticateAgency(Request $request)
{
    if (Auth::guard('agency')->attempt($request->only('email', 'password'))) {
        $request->session()->regenerate();
        return Inertia::location(route('agencyHome'));
    } else {
        Auth::logout();
        return Inertia::render('YourLoginFormComponent', [
            'error' => 'You are not authorized to access this resource',
        ])->withInput($request->only('email'));
    }
}

Replace YourLoginFormComponent with the name of your Vue.js login form component.

In your Vue.js login form component, make sure to handle and display the error message:

<template>
  <!-- Your form markup -->
  <div v-if="error">{{ error }}</div>
</template>

<script>
export default {
  props: {
    error: String,
  },
  // rest of your component code
};
</script>

By using Inertia's native methods, you should be able to handle redirection and display error messages in your Laravel + Inertia.js application.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

baha bahacherni Joined 11 Apr 2023

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.