feat: add delayed redirect with sweetalert timer on auth
This commit is contained in:
parent
d2a705732c
commit
ee51d217d7
|
|
@ -42,10 +42,12 @@ public function login(Request $request)
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
if ($user->hasRole('admin')) {
|
if ($user->hasRole('admin')) {
|
||||||
return redirect()->route('admin.dashboard')->with('success', 'Login berhasil sebagai admin.');
|
return back()->with('auth_success', 'Login berhasil sebagai admin.')
|
||||||
|
->with('redirect_url', route('admin.dashboard'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('home')->with('success', 'Login berhasil.');
|
return back()->with('auth_success', 'Login berhasil.')
|
||||||
|
->with('redirect_url', route('home'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(Request $request)
|
public function register(Request $request)
|
||||||
|
|
@ -77,7 +79,8 @@ public function register(Request $request)
|
||||||
Auth::login($user);
|
Auth::login($user);
|
||||||
$request->session()->regenerate();
|
$request->session()->regenerate();
|
||||||
|
|
||||||
return redirect()->route('home')->with('success', 'Registrasi berhasil. Selamat datang!');
|
return back()->with('auth_success', 'Registrasi berhasil. Selamat datang!')
|
||||||
|
->with('redirect_url', route('home'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return back()->withInput()
|
return back()->withInput()
|
||||||
->with('error_title', 'Registrasi Gagal')
|
->with('error_title', 'Registrasi Gagal')
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,19 @@
|
||||||
|
@if (session('auth_success'))
|
||||||
|
<script>
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'success',
|
||||||
|
title: 'Berhasil!',
|
||||||
|
text: @json(session('auth_success')),
|
||||||
|
timer: 2000,
|
||||||
|
timerProgressBar: true,
|
||||||
|
showConfirmButton: false,
|
||||||
|
willClose: () => {
|
||||||
|
window.location.href = @json(session('redirect_url'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
|
|
||||||
@if (session('success'))
|
@if (session('success'))
|
||||||
<script>
|
<script>
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue