vanilla javascript jwt authentication laravel

Solutions on MaxInterview for vanilla javascript jwt authentication laravel by the best coders in the world

showing results for - "vanilla javascript jwt authentication laravel"
Alessandra
17 Apr 2020
1In my guest RedirectIfAuthenticated middleware check for cookie, if exists, setToken which in turn sets Guard to Authenticated and will always redirect to /home if token is available and valid:
2
3public function handle($request, Closure $next, $guard = null)
4{
5    if ($request->hasCookie('access_token')) {
6        Auth::setToken($request->cookie('access_token'));
7    }
8
9    if (Auth::guard($guard)->check()) {
10        return redirect('/home');
11    }
12
13    return $next($request);
14}
15
16And In my post-auth Routes middleware I also setToken and if its valid and exists, will allow access, otherwise will throw a range of JWT errors which just redirect to pre-auth view:
17
18public function handle($request, Closure $next)
19{
20    JWTAuth::setToken($request->cookie('access_token'))->authenticate();
21
22    return $next($request);
23}
similar questions