Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add login expiration notification #6738

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1748,11 +1748,13 @@ core:
titles:
tip: Tip
warning: Warning
login_expired: Login expired
descriptions:
cannot_be_recovered: This operation is irreversible.
editor_not_found: >-
No editor found that matches the {raw_type} format. Please check if
the editor plugin has been installed.
login_expired: The current session has expired. Click Confirm to go to the login page. Please ensure that the current content is saved. You can click Cancel to manually copy any unsaved content.
filters:
results:
keyword: "Keyword: {keyword}"
Expand Down
2 changes: 2 additions & 0 deletions ui/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1635,9 +1635,11 @@ core:
titles:
tip: 提示
warning: 警告
login_expired: 登录已过期
descriptions:
cannot_be_recovered: 该操作不可恢复。
editor_not_found: 未找到符合 {raw_type} 格式的编辑器,请检查是否已安装编辑器插件。
login_expired: 当前登录已过期,点击确定跳转到登录页面,请确保当前内容已保存,你可以点击取消手动复制未保存的内容。
filters:
results:
keyword: 关键词:{keyword}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,11 @@ core:
titles:
tip: 提示
warning: 警告
login_expired: 登入已過期
descriptions:
cannot_be_recovered: 該操作不可恢復。
editor_not_found: 未找到符合 {raw_type} 格式的編輯器,請檢查是否已安裝編輯器插件。
login_expired: 當前登入已過期,點擊確定跳轉到登入頁面,請確保當前內容已保存,你可以點擊取消手動複製未保存的內容。
filters:
results:
keyword: 關鍵字:{keyword}
Expand Down
21 changes: 17 additions & 4 deletions ui/src/setup/setupApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { i18n } from "@/locales";
import { axiosInstance } from "@halo-dev/api-client";
import { Toast } from "@halo-dev/components";
import { Dialog, Toast } from "@halo-dev/components";
import type { AxiosError } from "axios";

export interface ProblemDetail {
Expand Down Expand Up @@ -44,9 +44,22 @@ export function setupApiClient() {
const { title, detail } = errorResponse.data;

if (status === 401) {
Toast.warning(i18n.global.t("core.common.toast.login_expired"));

// TODO: show dialog
Dialog.warning({
title: i18n.global.t("core.common.dialog.titles.login_expired"),
description: i18n.global.t(
"core.common.dialog.descriptions.login_expired"
),
confirmType: "secondary",
confirmText: i18n.global.t("core.common.buttons.confirm"),
cancelText: i18n.global.t("core.common.buttons.cancel"),
uniqueId: "login_expired",
onConfirm: () => {
const currentPath = `${location.pathname}${location.search}`;
location.href = `/login?redirect_uri=${encodeURIComponent(
currentPath
)}`;
},
});

return Promise.reject(error);
}
Expand Down
Loading