Redo logout 2
This commit is contained in:
parent
0bcc6e3f3f
commit
0f45244457
11 changed files with 24 additions and 34 deletions
|
@ -687,7 +687,7 @@ export default function Gallery() {
|
|||
}, [collections, hiddenCollections]);
|
||||
|
||||
const showSessionExpiredMessage = () => {
|
||||
setDialogMessage(getSessionExpiredMessage());
|
||||
setDialogMessage(getSessionExpiredMessage(logout));
|
||||
};
|
||||
|
||||
const syncWithRemote = async (force = false, silent = false) => {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import log from "@/next/log";
|
||||
import { putAttributes } from "@ente/accounts/api/user";
|
||||
import { logoutUser } from "@ente/accounts/services/user";
|
||||
import { getRecoveryKey } from "@ente/shared/crypto/helpers";
|
||||
import { ApiError } from "@ente/shared/error";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { getEndpoint, getFamilyPortalURL } from "@ente/shared/network/api";
|
||||
|
@ -104,10 +102,6 @@ export const getRoadmapRedirectURL = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
export const clearFiles = async () => {
|
||||
await localForage.clear();
|
||||
};
|
||||
|
||||
export const isTokenValid = async (token: string) => {
|
||||
try {
|
||||
const resp = await HTTPService.get(
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { ensureElectron } from "@/next/electron";
|
||||
import { AppUpdate } from "@/next/types/ipc";
|
||||
import { logoutUser } from "@ente/accounts/services/user";
|
||||
import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";
|
||||
import AutoAwesomeOutlinedIcon from "@mui/icons-material/AutoAwesomeOutlined";
|
||||
import InfoOutlined from "@mui/icons-material/InfoRounded";
|
||||
|
@ -121,14 +120,16 @@ export const getSubscriptionPurchaseSuccessMessage = (
|
|||
),
|
||||
});
|
||||
|
||||
export const getSessionExpiredMessage = (): DialogBoxAttributes => ({
|
||||
export const getSessionExpiredMessage = (
|
||||
action: () => void,
|
||||
): DialogBoxAttributes => ({
|
||||
title: t("SESSION_EXPIRED"),
|
||||
content: t("SESSION_EXPIRED_MESSAGE"),
|
||||
|
||||
nonClosable: true,
|
||||
proceed: {
|
||||
text: t("LOGIN"),
|
||||
action: logoutUser,
|
||||
action,
|
||||
variant: "accent",
|
||||
},
|
||||
});
|
||||
|
|
|
@ -45,7 +45,6 @@ import { useRouter } from "next/router";
|
|||
import { useEffect, useState } from "react";
|
||||
import { getSRPAttributes } from "../api/srp";
|
||||
import { PAGES } from "../constants/pages";
|
||||
import { logoutUser } from "../services/logout";
|
||||
import {
|
||||
configureSRP,
|
||||
generateSRPSetupAttributes,
|
||||
|
@ -53,7 +52,7 @@ import {
|
|||
} from "../services/srp";
|
||||
import { SRPAttributes } from "../types/srp";
|
||||
|
||||
export default function Credentials({ appContext, appName }: PageProps) {
|
||||
export default function Credentials({ appContext, appName, logout }: PageProps) {
|
||||
const [srpAttributes, setSrpAttributes] = useState<SRPAttributes>();
|
||||
const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();
|
||||
const [user, setUser] = useState<User>();
|
||||
|
@ -275,7 +274,7 @@ export default function Credentials({ appContext, appName }: PageProps) {
|
|||
<LinkButton onClick={redirectToRecoverPage}>
|
||||
{t("FORGOT_PASSWORD")}
|
||||
</LinkButton>
|
||||
<LinkButton onClick={logoutUser}>
|
||||
<LinkButton onClick={logout}>
|
||||
{t("CHANGE_EMAIL")}
|
||||
</LinkButton>
|
||||
</FormPaperFooter>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import log from "@/next/log";
|
||||
import { putAttributes } from "@ente/accounts/api/user";
|
||||
import { logoutUser } from "@ente/accounts/services/logout";
|
||||
import { configureSRP } from "@ente/accounts/services/srp";
|
||||
import { generateKeyAndSRPAttributes } from "@ente/accounts/utils/srp";
|
||||
import {
|
||||
|
@ -30,7 +29,7 @@ import {
|
|||
import { KeyAttributes, User } from "@ente/shared/user/types";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
export default function Generate({ appContext, appName }: PageProps) {
|
||||
export default function Generate({ appContext, appName, logout }: PageProps) {
|
||||
const [token, setToken] = useState<string>();
|
||||
const [user, setUser] = useState<User>();
|
||||
const [recoverModalView, setRecoveryModalView] = useState(false);
|
||||
|
@ -113,7 +112,7 @@ export default function Generate({ appContext, appName }: PageProps) {
|
|||
buttonText={t("SET_PASSPHRASE")}
|
||||
/>
|
||||
<FormPaperFooter>
|
||||
<LinkButton onClick={logoutUser}>
|
||||
<LinkButton onClick={logout}>
|
||||
{t("GO_BACK")}
|
||||
</LinkButton>
|
||||
</FormPaperFooter>
|
||||
|
|
|
@ -2,7 +2,6 @@ import log from "@/next/log";
|
|||
import { recoverTwoFactor, removeTwoFactor } from "@ente/accounts/api/user";
|
||||
import { PAGES } from "@ente/accounts/constants/pages";
|
||||
import { TwoFactorType } from "@ente/accounts/constants/twofactor";
|
||||
import { logoutUser } from "@ente/accounts/services/logout";
|
||||
import { PageProps } from "@ente/shared/apps/types";
|
||||
import { VerticallyCentered } from "@ente/shared/components/Container";
|
||||
import { DialogBoxAttributesV2 } from "@ente/shared/components/DialogBoxV2/types";
|
||||
|
@ -32,6 +31,7 @@ bip39.setDefaultWordlist("english");
|
|||
export default function Recover({
|
||||
appContext,
|
||||
twoFactorType = TwoFactorType.TOTP,
|
||||
logout,
|
||||
}: PageProps) {
|
||||
const [encryptedTwoFactorSecret, setEncryptedTwoFactorSecret] =
|
||||
useState<B64EncryptionResult>(null);
|
||||
|
@ -77,7 +77,7 @@ export default function Recover({
|
|||
e instanceof ApiError &&
|
||||
e.httpStatusCode === HttpStatusCode.NotFound
|
||||
) {
|
||||
logoutUser();
|
||||
logout();
|
||||
} else {
|
||||
log.error("two factor recovery page setup failed", e);
|
||||
setDoesHaveEncryptedRecoveryKey(false);
|
||||
|
|
|
@ -3,7 +3,7 @@ import VerifyTwoFactor, {
|
|||
VerifyTwoFactorCallback,
|
||||
} from "@ente/accounts/components/two-factor/VerifyForm";
|
||||
import { PAGES } from "@ente/accounts/constants/pages";
|
||||
import { logoutUser } from "@ente/accounts/services/logout";
|
||||
|
||||
import type { PageProps } from "@ente/shared/apps/types";
|
||||
import { VerticallyCentered } from "@ente/shared/components/Container";
|
||||
import FormPaper from "@ente/shared/components/Form/FormPaper";
|
||||
|
@ -19,7 +19,7 @@ import { t } from "i18next";
|
|||
import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const TwoFactorVerify: React.FC<PageProps> = () => {
|
||||
export const TwoFactorVerify: React.FC<PageProps> = ({ logout }: PageProps) => {
|
||||
const [sessionID, setSessionID] = useState("");
|
||||
|
||||
const router = useRouter();
|
||||
|
@ -60,7 +60,7 @@ export const TwoFactorVerify: React.FC<PageProps> = () => {
|
|||
e instanceof ApiError &&
|
||||
e.httpStatusCode === HttpStatusCode.NotFound
|
||||
) {
|
||||
logoutUser();
|
||||
logout();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ export const TwoFactorVerify: React.FC<PageProps> = () => {
|
|||
>
|
||||
{t("LOST_DEVICE")}
|
||||
</LinkButton>
|
||||
<LinkButton onClick={logoutUser}>
|
||||
<LinkButton onClick={logout}>
|
||||
{t("CHANGE_EMAIL")}
|
||||
</LinkButton>
|
||||
</FormPaperFooter>
|
||||
|
|
|
@ -16,7 +16,7 @@ import SingleInputForm, {
|
|||
import { ApiError } from "@ente/shared/error";
|
||||
import { getAccountsURL } from "@ente/shared/network/api";
|
||||
import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore";
|
||||
import { clearFiles } from "@ente/shared/storage/localForage/helpers";
|
||||
import localForage from "@ente/shared/storage/localForage";
|
||||
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
|
||||
import {
|
||||
getLocalReferralSource,
|
||||
|
@ -29,11 +29,10 @@ import { HttpStatusCode } from "axios";
|
|||
import { useRouter } from "next/router";
|
||||
import { putAttributes, sendOtt, verifyOtt } from "../api/user";
|
||||
import { PAGES } from "../constants/pages";
|
||||
import { logoutUser } from "../services/logout";
|
||||
import { configureSRP } from "../services/srp";
|
||||
import { SRPSetupAttributes } from "../types/srp";
|
||||
|
||||
export default function VerifyPage({ appContext, appName }: PageProps) {
|
||||
export default function VerifyPage({ appContext, appName, logout }: PageProps) {
|
||||
const [email, setEmail] = useState("");
|
||||
const [resend, setResend] = useState(0);
|
||||
|
||||
|
@ -121,7 +120,7 @@ export default function VerifyPage({ appContext, appName }: PageProps) {
|
|||
await configureSRP(srpSetupAttributes);
|
||||
}
|
||||
}
|
||||
clearFiles();
|
||||
localForage.clear();
|
||||
setIsFirstLogin(true);
|
||||
const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL);
|
||||
InMemoryStore.delete(MS_KEYS.REDIRECT_URL);
|
||||
|
@ -191,7 +190,7 @@ export default function VerifyPage({ appContext, appName }: PageProps) {
|
|||
)}
|
||||
{resend === 1 && <span>{t("SENDING")}</span>}
|
||||
{resend === 2 && <span>{t("SENT")}</span>}
|
||||
<LinkButton onClick={logoutUser}>
|
||||
<LinkButton onClick={logout}>
|
||||
{t("CHANGE_EMAIL")}
|
||||
</LinkButton>
|
||||
</FormPaperFooter>
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { clearCaches } from "@/next/blob-cache";
|
||||
import log from "@/next/log";
|
||||
import InMemoryStore from "@ente/shared/storage/InMemoryStore";
|
||||
import { clearFiles } from "@ente/shared/storage/localForage";
|
||||
import loc } from "@ente/shared/storage/localForage";
|
||||
import { clearData } from "@ente/shared/storage/localStorage";
|
||||
import { clearKeys } from "@ente/shared/storage/sessionStorage";
|
||||
import { logout as remoteLogout } from "../api/user";
|
||||
import localForage from "@ente/shared/storage/localForage";
|
||||
|
||||
/**
|
||||
* Logout sequence common to all apps that rely on the accounts package.
|
||||
|
@ -43,8 +44,8 @@ export const accountLogout = async () => {
|
|||
log.error("Ignoring error when clearing caches", e);
|
||||
}
|
||||
try {
|
||||
await clearFiles();
|
||||
await localForage.clear();
|
||||
} catch (e) {
|
||||
log.error("Ignoring error when clearing files", e);
|
||||
log.error("Ignoring error when clearing local forage", e);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,4 +10,5 @@ export interface PageProps {
|
|||
};
|
||||
appName: APPS;
|
||||
twoFactorType?: TwoFactorType;
|
||||
logout: () => void;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,3 @@ if (haveWindow()) {
|
|||
}
|
||||
|
||||
export default localForage;
|
||||
|
||||
export const clearFiles = async () => {
|
||||
await localForage.clear();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue