If I have a url: <host>/login/?token=<valid_backend_token>, where valid_backend_token is an authentication token that my backend produced. Using this token, I can pretty much do anything that I want for my use case (including fetching user profile, etc.). Is there a way I can use this token to authenticate an user in Nuxt?
Currently, I tried something like this:
mounted() {
if (this.$route.query.token) {
this.$axios
.get("/profile/", {
headers: {
Authorization: "Token " + this.$route.query.token,
},
})
.then((resp) => {
this.$axios.setToken(this.$route.query.token, "Token");
this.$auth.setUser(resp.data);
this.$router.push("/");
});
}
},
Of course, this doesn't authenticate my user (since $auth.loggedIn is false). $auth.user is of course set and I can visit the profile page (if I disable auth middleware). Besides $auth.loggedIn being false, my $this.axios.get/put/etc. would throw the error (even though there's no need to refresh tokens in my case and I have already set it):
ExpiredAuthSessionError: Both token and refresh token have expired. Your request was aborted.
How can I make this authentication work?