Assumption
I am implementing a login function in nuxt/auth. I want to implement a guest login function, but when I press the button to log in as a guest, it doesn't go to /search, it goes back to user/login. I would like it not to go to the login page.
The specified page is displayed for a moment, but user/login is displayed immediately.
What we want to achieve
I want to be redirected to a specified page after pressing the guest login button.
Code
Pages with a 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') // I get back to the login page without going to /search.
}
}
}
</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
}
}
}
},