Skip to content

Commit

Permalink
fix changes according to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsinayoob committed Dec 22, 2024
1 parent c1e5815 commit 22c941b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LoginContainer from '@/components/Login/LoginContainer';
import PageContainer from '@/components/PageContainer';
import { ToastStatus, useToast } from '@/dls/Toast/Toast';
import ChaptersData from '@/types/ChaptersData';
import { BANNED_USER_ERROR_ID } from '@/utils/auth/constants';
import { getAllChaptersData } from '@/utils/chapter';
import { getLoginNavigationUrl } from '@/utils/navigation';
import AuthError from 'types/AuthError';
Expand All @@ -26,6 +27,9 @@ const LoginPage: NextPage<Props> = () => {
if (errorId in AuthError) {
return t(`login-error.${errorId}`);
}
if (errorId === BANNED_USER_ERROR_ID) {
return t(`login-error.${AuthError.BannedUserError}`);
}
return t(`login-error.${AuthError.AuthenticationError}`);
},
[t],
Expand Down
7 changes: 4 additions & 3 deletions src/utils/auth/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { configureRefreshFetch } from 'refresh-fetch';
import { getTimezone } from '../datetime';
import { prepareGenerateMediaFileRequestData } from '../media/utils';

import { BANNED_USER_ERROR_ID } from './constants';
import generateSignature from './signature';
import BookmarkByCollectionIdQueryParams from './types/BookmarkByCollectionIdQueryParams';
import GetAllNotesQueryParams from './types/Note/GetAllNotesQueryParams';
Expand All @@ -27,7 +28,6 @@ import { CreateGoalRequest, Goal, GoalCategory, UpdateGoalRequest } from '@/type
import { Note } from '@/types/auth/Note';
import { Response } from '@/types/auth/Response';
import { StreakWithMetadataParams, StreakWithUserMetadata } from '@/types/auth/Streak';
import AuthError from '@/types/AuthError';
import GenerateMediaFileRequest, { MediaType } from '@/types/Media/GenerateMediaFileRequest';
import MediaRenderError from '@/types/Media/MediaRenderError';
import { Mushaf } from '@/types/QuranReader';
Expand Down Expand Up @@ -101,6 +101,7 @@ const IGNORE_ERRORS = [
const handleErrors = async (res) => {
const body = await res.json();
const error = body?.error || body?.details?.error;
const errorName = body?.name || body?.details?.name;

// sometimes FE needs to handle the error from the API instead of showing a general something went wrong message
const shouldIgnoreError = IGNORE_ERRORS.includes(error?.code);
Expand All @@ -109,9 +110,9 @@ const handleErrors = async (res) => {
}
// const toast = useToast();

if (error?.code === AuthError.BannedUserError) {
if (errorName === BANNED_USER_ERROR_ID) {
await logoutUser();
return Router.push(`/login?error=${AuthError.BannedUserError}`);
return Router.push(`/login?error=${errorName}`);
}

throw new Error(body?.message);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/auth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export const NOTIFICATION_SUBSCRIBER_COOKIE_NAME = addEnvSuffixToAuthCookie('not
export const DEFAULT_PHOTO_URL = `https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&f=y`;

export const AUTH_ONBOARDING_ANNOUNCEMENT_TYPE = 'auth-onboarding';

export const BANNED_USER_ERROR_ID = 'external.banned';

0 comments on commit 22c941b

Please sign in to comment.