DEV Community

Discussion on: The Complete Guide to User Authentication with the Amplify Framework

Collapse
 
valenciahq profile image
Alejandro Valencia

hi! is there a way to avoid "uncaught (in promise) not authenticated" error being showed in console on:

await Auth.currentAuthenticatedUser()
.then(user => {
...some stuff
})
.catch(e => {
history.push("/auth");
});

The app will redirect to /auth each time is not authenticated but we dont want to see not authenticated error in console in production

Collapse
 
mrichman profile image
Mark Richman

Did you ever figure this out? I get that same error.

Collapse
 
rtdemetri profile image
Demetrios Christopher

In your .then(), provide an onRejected clause:

Auth.currentAuthenticatedUser().then((user) => { ... }, (error) => { ... }).catch((error) => { ... })

The catch is there to catch something wrong that you did in your onResolved or onRejected clauses, not to catch the fact that the promise was rejected and never resolved. I hope this helps!

Alternatively, you can turn the promises into observables and deal with them as such.