Scenario
Currently, I am working on integrating a login feature using nuxt/auth
. My goal is to include a guest login option. However, upon selecting the guest login button, instead of being directed to /search
, the page goes back to user/login
. This behavior is not desired as I want to avoid redirecting to the login page after choosing the guest login option.
Although the specified page briefly appears, it quickly switches back to display user/login
.
Objective
The aim is to successfully redirect to a specific page after clicking the guest login button.
Implementation
Pages containing the guest login button:
<script>
import * as url from '@/store/constants/url'
export default {
data ({ $config: { APP_NAME } }) {
return {
APP_NAME,
}
},
methods: {
guest () {
・
・
.then((response) => {
・
・
this.$auth.loginWith('local', {data: {
email: response.email,
password: "xxxxxx"
}})
})
this.$router.replace('/search') // Issue with redirection to /search after clicking guest login button
}
}
}
</script>
nuxt.config.js
auth: {
token: {
global: true
},
redirect: {
login: '/user/login',
logout: '/user/login',
callback: false,
home: '/'
},
strategies: {
local: {
endpoints: {
login: { url: '/api/v1/auth/sign_in', method: 'post', propertyName: 'token' },
logout: { url: '/api/v1/auth/sign_out', method: 'delete' },
user: false
}
}
}
},