Skip to content

Commit 69520ed

Browse files
mohsinayoobosamasayed
authored andcommitted
fix: resolves ban user action to show message and logout (#2263)
1 parent 42deeea commit 69520ed

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

locales/en/login.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"login-cta": "Log-in or Sign up now:",
1515
"login-error": {
1616
"AuthenticationError": "Authentication failed. Please try again later",
17-
"TokenExpiredError": "You have been logged out, please login again."
17+
"TokenExpiredError": "You have been logged out, please login again.",
18+
"BannedUserError": "Sorry, Your account is banned. Contact Quran.Foundation."
1819
},
1920
"login-title": "Login to Quran.com",
2021
"other-options": "Other Login Options",

src/pages/login.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ const LoginPage: NextPage<Props> = () => {
3434
useEffect(() => {
3535
if (query.error) {
3636
const errorMessage = getErrorMessage(query.error);
37-
toast(errorMessage, {
38-
status: ToastStatus.Error,
37+
replace(getLoginNavigationUrl(), null, { shallow: true }).then(() => {
38+
toast(errorMessage, {
39+
status: ToastStatus.Error,
40+
});
3941
});
40-
replace(getLoginNavigationUrl(), null, { shallow: true });
4142
}
4243
}, [query.error, toast, replace, t, getErrorMessage]);
4344

src/utils/auth/api.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable max-lines */
22
import { NextApiRequest } from 'next';
3+
import Router from 'next/router';
34
import { configureRefreshFetch } from 'refresh-fetch';
45

56
import { getTimezone } from '../datetime';
@@ -26,6 +27,7 @@ import { CreateGoalRequest, Goal, GoalCategory, UpdateGoalRequest } from '@/type
2627
import { Note } from '@/types/auth/Note';
2728
import { Response } from '@/types/auth/Response';
2829
import { StreakWithMetadataParams, StreakWithUserMetadata } from '@/types/auth/Streak';
30+
import AuthError from '@/types/AuthError';
2931
import GenerateMediaFileRequest, { MediaType } from '@/types/Media/GenerateMediaFileRequest';
3032
import MediaRenderError from '@/types/Media/MediaRenderError';
3133
import { Mushaf } from '@/types/QuranReader';
@@ -98,11 +100,20 @@ const IGNORE_ERRORS = [
98100

99101
const handleErrors = async (res) => {
100102
const body = await res.json();
103+
const error = body?.error || body?.details?.error;
104+
101105
// sometimes FE needs to handle the error from the API instead of showing a general something went wrong message
102-
const shouldIgnoreError = IGNORE_ERRORS.includes(body?.error?.code);
106+
const shouldIgnoreError = IGNORE_ERRORS.includes(error?.code);
103107
if (shouldIgnoreError) {
104108
return body;
105109
}
110+
// const toast = useToast();
111+
112+
if (error?.code === AuthError.BannedUserError) {
113+
await logoutUser();
114+
return Router.push(`/login?error=${AuthError.BannedUserError}`);
115+
}
116+
106117
throw new Error(body?.message);
107118
};
108119

types/AuthError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ enum AuthError {
22
AuthenticationError = 'AuthenticationError',
33
TokenExpiredError = 'TokenExpiredError',
44
GenerateCookieError = 'GenerateCookieError',
5+
BannedUserError = 'BannedUserError',
56
}
67
export default AuthError;

0 commit comments

Comments
 (0)