Closed ahoiroman closed 2 years ago
try 2.0.21
2.0.21
has the same problem.
what scheme are you using?
auth: {
globalMiddleware: true,
redirect: {
home: '/dashboard',
logout: '/',
login: '/auth/signin',
callback: '/backend/login',
},
strategies: {
// @ts-ignore
api: {
provider: 'laravel/sanctum',
url: process.env.NUXT_PUBLIC_APP_URL,
cookie: {
server: true,
name: 'XSRF-TOKEN',
},
endpoints: {
csrf: {
url: '/backend/sanctum/csrf-cookie'
},
login: {
url: '/backend/login'
},
logout: {
url: '/backend/logout'
},
user: {
url: '/backend/api/auth/me'
}
},
user: {
property: {
client: false,
server: false
},
autoFetch: true
}
},
}
},
Update: For testing purposes I also removed all custom middleware, which is redirecting the user in some cases. But removing all custom middleware and restarting npm run dev
did not solve this issue.
As I said before: It worked in versions < 2.0.19
Im not getting the redirects
I will build a reproducer (if I can) within the next days.
What I found so far:
If the credentials are not valid, the Laravel-Backend sends:
FetchError: 401 Unauthorized (http://web.example.test/backend/login)
FetchError — ohmyfetch.fb8dc89e.mjs:6
createFetchError — ohmyfetch.fb8dc89e.mjs:18
onError — ohmyfetch.fb8dc89e.mjs:96
asyncFunctionResume
(anonyme Funktion)
promiseReactionJobWithoutPromise
promiseReactionJob
Now within the Nuxt-auth module, the init-function is being triggered.
[Log] Logging in (auth.mjs, line 109)
[Log] Redirecting in init method (auth.mjs, line 72)
[Log] Redirecting to – {name: "logout"} (auth.mjs, line 250)
[Error] Failed to load resource: the server responded with a status of 401 (Unauthorized) (login, line 0)
[Log] error -> this.callOnError (auth.mjs, line 121)
[Log] FetchError: 401 Unauthorized (http://web.example.test/backend/login) (auth.mjs, line 122)
[Log] Promise.reject(error) (auth.mjs, line 124)
So for some reason, on a login attempt with wrong credentials, this part is triggered: https://github.com/Teranode/nuxt-module-alternatives/blob/master/%40nuxtjs-alt/auth/src/runtime/core/auth.ts#L113
try the update i pushed
Hm, no... I am not sure what changed, as I don't see the changes here in the repo atm.
@Teranode v2.0.22 doesn't seem to solve it
one more time 2.0.23
I think it has to do with the routeOption
util so I'm hoping this fixes it.
@Teranode unfortunately, doesnt work with v2.0.23 too
@ahoiroman what does your login page template look like?
The 2.0.23
does not solve the problem here.
My login page is pretty condensed to
<template>
<div class="flex min-h-screen p-8">
<div class="space-y-6">
<div>
<label>Email</label>
<div class="mt-1">
<input v-model="form.email" name="form.email"/>
</div>
</div>
<div class="space-y-1">
<label class="block text-heading-base text-sm text-gray-800" for="form.secret">
Secret
</label>
<div class="mt-1">
<input v-model="form.secret" name="form.secret"/>
</div>
</div>
<button @click="onSubmit">SignIn</button>
</div>
</div>
</template>
<script setup>
definePageMeta({
auth: 'guest',
title: 'Sign In',
layout: 'blank'
});
const {$auth} = useNuxtApp();
const form = ref({
name: null,
email: "",
secret: null
});
function onSubmit() {
$auth.login({
body: {
name: form.value.name,
email: form.value.email,
secret: form.value.secret
}
})
.catch((e) => {
console.log(e)
});
}
</script>
I removed all other components, validations etc. that could possibly interfere with nuxt-alt/auth.
Im really not reproducing the issues you are having.
I've updtaed github with the changes so far.
@sumitkolhe you had the same problem? I will try to create a reproducer this weekend, but I can't promise.
@ahoiroman yes, on wrong credentials it takes to the path specified in logout route, for me, even on right credentials it does the same but once the server returns with 200 response, it redirects properly.
so, if login page : /auth/login
and logout url : /auth
then on wrong creds, it will redirect to /auth
,
while for right creds : /auth/login
-> /auth
-> /dashboard
no matter right/wrong creds it initially redirects to the logout route
@ahoiroman add middleware: ['auth']
to definePageMeta
?
Nvm realised you are using globalMiddleware
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Environment
Reproduction
Create a login function like:
If I now log in using wrong credentials and the API returns HTTP 401, the user is being redirected to
/
instead of remaining on the login-page. Theconsole.log("Can't log in");
fires.This issue was introduced in
2.0.19
and is also present in2.0.20
. Using2.0.18
it works as expected.Describe the bug
User is being redirected when entering wrong credentials instead of remaining on the login page.
Additional context
No response
Logs
No response