Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 6fd4696

Browse files
committed
fix: display auth error
1 parent fa0244f commit 6fd4696

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/pages/auth/ProviderAuth.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from "react";
12
import { useContext } from "react";
23
import Box from "@mui/material/Box";
34
import * as buttons from "~/components/Buttons";
@@ -13,9 +14,10 @@ interface Props {
1314

1415
export default function ProviderAuth({ providers }: Props) {
1516
const { loginOauth } = useContext(AuthContext);
17+
const [error, setError] = useState<string>();
1618

1719
return (
18-
<Card sx={{ width: "100%" }}>
20+
<Card sx={{ width: "100%" }} error={error}>
1921
<CardHeader
2022
title="Authentication"
2123
subtitle="Login with your provider"
@@ -33,17 +35,20 @@ export default function ProviderAuth({ providers }: Props) {
3335
sx={{
3436
mb: providers?.gitlab || providers.bitbucket ? 4 : 0,
3537
}}
36-
onClick={() => loginOauth?.("github")}
38+
onClick={() => loginOauth?.("github").catch(setError)}
3739
/>
3840
)}
3941
{providers?.gitlab && (
4042
<GitlabButton
4143
sx={{ mb: providers?.bitbucket ? 4 : 0 }}
42-
onClick={() => loginOauth?.("gitlab")}
44+
onClick={() => loginOauth?.("gitlab").catch(setError)}
4345
/>
4446
)}
4547
{providers?.bitbucket && (
46-
<BitbucketButton onClick={() => loginOauth?.("bitbucket")} />
48+
<BitbucketButton
49+
sx={{ mb: error ? 4 : 0 }}
50+
onClick={() => loginOauth?.("bitbucket").catch(setError)}
51+
/>
4752
)}
4853
</Box>
4954
</Card>

src/pages/auth/actions.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ interface FetchUserReturnValue {
1111
user?: User;
1212
accounts: Array<ConnectedAccount>;
1313
setUser: (u: User) => void;
14-
setError: SetError;
1514
}
1615

1716
interface FetchUserResponse {
@@ -59,7 +58,7 @@ export const useFetchUser = (): FetchUserReturnValue => {
5958
};
6059
}, [api, token]);
6160

62-
return { error, user, accounts, loading, setError, setUser };
61+
return { error, user, accounts, loading, setUser };
6362
};
6463

6564
interface Providers {
@@ -97,7 +96,6 @@ export const logout = () => (): void => {
9796

9897
interface LoginOauthProps {
9998
setUser: (u: User) => void;
100-
setError: SetError;
10199
}
102100

103101
export interface LoginOauthReturnValue {
@@ -109,9 +107,9 @@ export interface LoginOauthReturnValue {
109107
// This one returns a function that returns another function.
110108
// The first function is used to inject the api props. The second
111109
// function produces an oauthlogin function based on the provider.
112-
export const loginOauth = ({ setUser, setError }: LoginOauthProps) => {
110+
export const loginOauth = ({ setUser }: LoginOauthProps) => {
113111
return (provider: Provider): Promise<LoginOauthReturnValue> => {
114-
return new Promise(resolve => {
112+
return new Promise((resolve, reject) => {
115113
let url = api.baseurl + `/auth/${provider}`;
116114

117115
const title = "oauthWindow";
@@ -146,21 +144,21 @@ export const loginOauth = ({ setUser, setError }: LoginOauthProps) => {
146144
});
147145
}
148146

149-
if (data?.success === false) {
147+
if (!data?.success) {
150148
if (data.email === false) {
151-
setError(
149+
reject(
152150
"We could not fetch your primary verified email from the provider. Make sure your email is verified."
153151
);
154152
} else if (data.error === "seats-full") {
155-
setError(
153+
reject(
156154
"Your license does not allow more seats. Upgrade your plan to accept new users."
157155
);
158156
} else if (data.error === "account-too-new") {
159-
setError(
157+
reject(
160158
"Your provider account is newly created. We do not accept new accounts. Please wait a few days."
161159
);
162160
} else {
163-
setError("An error occurred while authenticating. Please retry.");
161+
reject("An error occurred while authenticating. Please retry.");
164162
}
165163
}
166164
};

0 commit comments

Comments
 (0)