Nuxt/Auth-Next Redirect after Login and Logout Not Working

31 Views Asked by At

I've been using @nuxtjs/auth-next package for a certain pages of my project. Here are my nuxt auth configurations...

    strategies: {
        policies: {
            scheme: 'local',
            token: {
                global: false,
                type: '',
                required: true
            },
            redirect: {
                login: '/my-policies',
                logout: '/my-policies/login',
                user: '/my-policies/login',
                home: '/my-policies'
            },
            endpoints: {
                login: { url: '/policies/login', method: 'post', propertyName: 'token'},
                logout: { url: '/policies/logout', method: 'delete'},
                user: { url: '/policies/user', method: 'get'}
            },
            user: {
                property: ''
            },
        },
    }

The problem is, redirects never work. The login endpoint responses successfully and the nuxt auth triggers the user request. When that one is also successful, it redirects me to my homepage which is "/". But in the redirect object in the nuxt.config file, I defined it to redirect to "/my-policies/" page.

Also when I logout by using this.$auth.logout(); it redirects me to homepage as well.

I tried to redirect the page manually but still no luck...

Also tried to work with rewriteRedirects. When I set it to false, it redirects me to "/login" page when I logout.

So, the redirect object in my config never work. Is there anything I'm missing? Thanks in advance.

1

There are 1 best solutions below

0
Ondřej On

I think you would like to use callbackUrl parameter in the authentification method.

 await signIn(credentials,{ callbackUrl: '/' });

Lets have a look into the documentation