[Vuejs]-Email/verify with VusJS SPA and Laravel

4👍

I`m a beginner in Laravel and Vue-Js. I have done my website with JWT auth. I manage the access to pages using routes as follows.

routes: [
{ path: "/profile", component: profile, meta: { requireAuth: true } },
// this can be access only by registered users
{ path: "/home", component: home }, //this route can be access by anyone


router.beforeEach((to, from, next) => {
  //console.log(Store.getters.role);
  if (to.meta.requireAuth) {
  next();

 }
 }
);

1👍

A Solution but I’m not sure if it would be the best one if you want to force the users to see only ‘Verify Email’ is to create a middleware and add it to SpaController:

class ForceRedirectToVerifyEmail extends Middleware
{
    /**
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string
     */
    protected function redirectTo($request)
    {
        if (auth()->check() && !auth()->user()->hasVerifiedEmail()) {
            return url('verify-email');//Or what ever need to redirect them as normly it would be handled in VueJS or ReactJs themselves.
        }
    }
}

Leave a comment