Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix showing error in UI on failed auth

Marcin Gębalaaa1244c980a6
diff --git a/saleor/static/dashboard-next/auth/AuthProvider.tsx b/saleor/static/dashboard-next/auth/AuthProvider.tsx
index aee2c973e6..54e8020b87 100644
--- a/saleor/static/dashboard-next/auth/AuthProvider.tsx
+++ b/saleor/static/dashboard-next/auth/AuthProvider.tsx
@@ -58,11 +58,17 @@ class AuthProvider extends React.Component<
this.logout();
}
if (tokenAuth.data) {
- this.setState({ user: tokenAuth.data.tokenCreate.user });
- setAuthToken(tokenAuth.data.tokenCreate.token, this.state.persistToken);
+ const user = tokenAuth.data.tokenCreate.user;
+ // FIXME: Now we set state also when auth fails and returned user is
+ // `null`, because the LoginView uses this `null` to display error.
+ this.setState({ user });
+ if (user) {
+ setAuthToken(tokenAuth.data.tokenCreate.token, this.state.persistToken);
+ }
}
- if (tokenVerify.data) {
- this.setState({ user: tokenVerify.data.tokenVerify.user });
+ if (tokenVerify.data && tokenVerify.data.tokenVerify.user) {
+ const user = tokenVerify.data.tokenVerify.user;
+ this.setState({ user });
}
}