Skip to content

Commit

Permalink
Merge pull request #120 from supertokens/fix/500
Browse files Browse the repository at this point in the history
fix: email verification failing issue
  • Loading branch information
rishabhpoddar authored Oct 9, 2023
2 parents 5f1f414 + a5f64b2 commit bf2bd7e
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.8.5] - 2023-10-5

- Fixes showing email verification UI even though it's not initialised.

## [0.8.4] - 2023-09-29

- Fixes dashboard signin form input styles issue.
Expand Down
2 changes: 1 addition & 1 deletion build/static/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/static/js/bundle.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashboard",
"version": "0.8.4",
"version": "0.8.5",
"private": true,
"dependencies": {
"@babel/core": "^7.16.0",
Expand Down
2 changes: 1 addition & 1 deletion src/api/user/email/verify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const useVerifyUserEmail = (): IUseVerifyUserEmailService => {
const response = await fetchData({
url: getApiUrl("/api/user/email/verify"),
method: "GET",
query: { userId },
query: { recipeUserId: userId },
});

const body = await response.json();
Expand Down
18 changes: 17 additions & 1 deletion src/ui/components/userDetail/loginMethods/LoginMethods.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React, { useCallback, useContext, useState } from "react";
import useUserService, { UpdateUserInformationResponse, type IUpdateUserInformationArgs } from "../../../../api/user";
import useDeleteUserService from "../../../../api/user/delete";
import useVerifyUserEmail from "../../../../api/user/email/verify";
import useVerifyUserTokenService from "../../../../api/user/email/verify/token";
import usePasswordResetService from "../../../../api/user/password/reset";
import useUnlinkService from "../../../../api/user/unlink";
import { getImageUrl } from "../../../../utils";
import { formatLongDate } from "../../../../utils/index";
import { PopupContentContext } from "../../../contexts/PopupContentContext";
import { UserRecipeType, type LoginMethod } from "../../../pages/usersList/types";
import { FEATURE_NOT_ENABLED_TEXT, UserRecipeType, type LoginMethod } from "../../../pages/usersList/types";
import CopyText from "../../copyText/CopyText";
import { LayoutPanel } from "../../layout/layoutPanel";
import TooltipContainer from "../../tooltip/tooltip";
import { useUserDetailContext } from "../context/UserDetailContext";
import {
getDeleteUserToast,
getInitlizeEmailVerificationRecipeTost,
getLoginMethodUnlinkConfirmationProps,
getSendEmailVerificationToast,
getUnlinkUserToast,
Expand Down Expand Up @@ -148,6 +150,7 @@ const Methods: React.FC<MethodProps> = ({
const { sendUserEmailVerification: sendUserEmailVerificationApi } = useVerifyUserTokenService();
const { showModal, showToast } = useContext(PopupContentContext);
const [emailError, setEmailError] = useState("");
const { getUserEmailVerificationStatus } = useVerifyUserEmail();

const trim = (val: string) => {
const len = val.length;
Expand All @@ -156,6 +159,13 @@ const Methods: React.FC<MethodProps> = ({

const sendUserEmailVerification = useCallback(
async (userId: string, tenantId: string | undefined) => {
const res = await getUserEmailVerificationStatus(userId);

if (res.status === FEATURE_NOT_ENABLED_TEXT) {
showToast(getInitlizeEmailVerificationRecipeTost());
return;
}

const isSend = await sendUserEmailVerificationApi(userId, tenantId);
showToast(getSendEmailVerificationToast(isSend));
return isSend;
Expand Down Expand Up @@ -195,6 +205,12 @@ const Methods: React.FC<MethodProps> = ({
[showModal, loginMethod.recipeUserId, changePassword]
);
const changeEmailVerificationStatus = async () => {
const res = await getUserEmailVerificationStatus(loginMethod.recipeUserId);

if (res.status === FEATURE_NOT_ENABLED_TEXT) {
showToast(getInitlizeEmailVerificationRecipeTost());
return;
}
await onUpdateEmailVerificationStatusCallback(loginMethod.recipeUserId, !loginMethod.verified, undefined);
await refetchAllData();
};
Expand Down
44 changes: 23 additions & 21 deletions src/ui/components/userDetail/userDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { PopupContentContext } from "../../contexts/PopupContentContext";
import { User, UserRecipeType } from "../../pages/usersList/types";
import { getMissingTenantIdModalProps } from "../common/modals/TenantIdModals";
import { OnSelectUserFunction } from "../usersListTable/UsersListTable";
import { UserDetailContextProvider, UserDetails, useUserDetailContext } from "./context/UserDetailContext";
import { UserDetailContextProvider } from "./context/UserDetailContext";
import { LoginMethods } from "./loginMethods/LoginMethods";
import "./tenantList/UserTenantsList.scss";
import "./userDetail.scss";
Expand Down Expand Up @@ -53,6 +53,7 @@ export const UserDetail: React.FC<UserDetailProps> = (props) => {
const [sessionList, setSessionList] = useState<SessionInfo[] | undefined>(undefined);
const [userMetaData, setUserMetaData] = useState<string | undefined>(undefined);
const [shouldShowLoadingOverlay, setShowLoadingOverlay] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState(false);

const { getUser, updateUserInformation } = useUserService();
const { getUserMetaData } = useMetadataService();
Expand All @@ -64,10 +65,6 @@ export const UserDetail: React.FC<UserDetailProps> = (props) => {
setUserDetail(JSON.parse(JSON.stringify(userDetailsResponse)));
}, []);

useEffect(() => {
void loadUserDetail();
}, [loadUserDetail]);

const { showToast } = useContext(PopupContentContext);

const updateUser = useCallback(
Expand Down Expand Up @@ -144,10 +141,6 @@ export const UserDetail: React.FC<UserDetailProps> = (props) => {
}
}, []);

useEffect(() => {
void fetchUserMetaData();
}, [fetchUserMetaData]);

const fetchSession = useCallback(async () => {
let response = await getSessionsForUser(user);

Expand All @@ -158,10 +151,6 @@ export const UserDetail: React.FC<UserDetailProps> = (props) => {
setSessionList(response);
}, []);

useEffect(() => {
void fetchSession();
}, [fetchSession]);

const showLoadingOverlay = () => {
setShowLoadingOverlay(true);
};
Expand All @@ -170,7 +159,27 @@ export const UserDetail: React.FC<UserDetailProps> = (props) => {
setShowLoadingOverlay(false);
};

if (userDetail === undefined) {
const fetchData = async () => {
setIsLoading(true);
await loadUserDetail();
await fetchUserMetaData();
await fetchSession();
setIsLoading(false);
};

const refetchAllData = async () => {
setShowLoadingOverlay(true);
await loadUserDetail();
await fetchUserMetaData();
await fetchSession();
setShowLoadingOverlay(false);
};

useEffect(() => {
void fetchData();
}, []);

if (userDetail === undefined || isLoading) {
return (
<div className="user-detail-page-loader">
<div className="loader"></div>
Expand Down Expand Up @@ -206,13 +215,6 @@ export const UserDetail: React.FC<UserDetailProps> = (props) => {
);
}

const refetchAllData = async () => {
setShowLoadingOverlay(true);
await loadUserDetail();
await fetchUserMetaData();
await fetchSession();
setShowLoadingOverlay(false);
};
const userFunctions = {
refetchAllData: refetchAllData,
updateUser: updateUser,
Expand Down
8 changes: 8 additions & 0 deletions src/ui/components/userDetail/userDetailForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,14 @@ export const getSendEmailVerificationToast = (isSuccessfull: boolean) => {
} as ToastNotificationProps;
};

export const getInitlizeEmailVerificationRecipeTost = () => {
return {
iconImage: getImageUrl("form-field-error-icon.svg"),
toastType: "error",
children: <>{"EmailVerification feature is not enabled"}</>,
} as ToastNotificationProps;
};

export const getEmailVerifiedToast = (isSuccessfull: boolean) => {
return {
iconImage: getImageUrl(isSuccessfull ? "checkmark-green.svg" : "form-field-error-icon.svg"),
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
* under the License.
*/

export const package_version = "0.8.4";
export const package_version = "0.8.5";

0 comments on commit bf2bd7e

Please sign in to comment.