websanova / vue-auth

A simple light-weight authentication library for Vue.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redirect : Erreur 401 on apache server and not a local wamp

itokia opened this issue · comments

Hello,
I have links that allow me to access specific pages of my application but when the page opens I am automatically redirected to my authentication page. So I added the redirect option in the following way which works locally under WAMP but not on my redhat 8 server. Which gives me back a 401 error. Do you know if there is an apache configuration to set up?

    this.$auth.login({
      fetchUser: true,
      data: this.form,
      staySignedIn: this.staySignedIn,
      redirect: {
        path: redirect ? redirect.from.fullPath : ''
      }
    })

mon auth.js

    plugins: {
      http: app.config.globalProperties.$api,
      router: router
    },
    drivers: {
      auth: driverAuthBearer,
      http: driverHttpAxios,
      router: driverRouterVueRouter
    },
    options: {
      rolesKey: 'role',
      notFoundRedirect: { name: 'login' },
      refreshData: {
        url: '/auth/login',
        method: 'GET',
        interval: 2,
        enabled: true
      }
    }
  })

Well this is separate from anything you would have on your server. Do you see an auth token in local storage/cookie?

Yes, my token exists. it's just the redirection to the original address that is not taken into account on the server.

'''const redirect = this.$auth.redirect();'''

Not really sure what you're asking here. The vue-auth plugin is for front end so it doesn't really have anything to do with the server other than dealing with tokens. If there is a redirect after login on your front end it should have nothing to do with server.

I managed to find the solution, I'll share it with you just in case.
You need to modify the quasar.config to change it to 'history' mode and not hash.

Then, for this to work properly under redhat8 you need to add the following apache conf:

        RewriteEngine On
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
        RewriteBase /
        RewriteRule ^index\.html$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.html [L]
        Header set Cache-Control "no-cache"
        Require local

And finally, put this in the js code:

const redirect = auth.redirect();
  auth
    .login({
      fetchUser: true,
      data: "",
      staySignedIn: true,
      redirect: {
        path: redirect ? redirect.from.fullPath : "",
      },
    })```