react-oidc-context icon indicating copy to clipboard operation
react-oidc-context copied to clipboard

Error handling when using signinResourceOwnerCredentials()

Open Burane opened this issue 2 years ago • 2 comments

        try {
            const user = await auth.signinResourceOwnerCredentials({
                username: values.email,
                password: values.password,
            })

            console.log(user)
        } catch (e: any) {
            console.log("error login !",e)
        }

is this code the catch block is never triggered, when the authentication failed the user is null but how can i have a error message ? https://authts.github.io/oidc-client-ts/#md:events didnt help

Burane avatar Dec 14 '23 14:12 Burane

there is auth.error but this value is not updated immediatly after

        await auth.signinResourceOwnerCredentials({
            username: values.email,
            password: values.password,
        })

        console.log(auth.error); // still undefined for some time even with a login error

Burane avatar Dec 14 '23 15:12 Burane

there is auth.error but this value is not updated immediatly after

That is by design of the reducer within this library, when you use the error in the render code it will work...

pamapa avatar Dec 15 '23 06:12 pamapa