Commit 0bae58ee authored by Chunchi Che's avatar Chunchi Che

optimize

parent 85a585f5
Pipeline #23219 passed with stages
in 11 minutes and 52 seconds
......@@ -14,9 +14,9 @@ export function getSSOSignInUrl(callbackUrl: string): string {
return url.toString();
}
export function getSSOSignOutUrl(returnUrl: string): string {
export function getSSOSignOutUrl(callbackUrl: string): string {
const params = new URLSearchParams({
redirect: returnUrl,
redirect: callbackUrl,
});
const url = new URL(NeosConfig.logoutUrl);
......
......@@ -9,7 +9,12 @@ import {
} from "react-router-dom";
import { useSnapshot } from "valtio";
import { CookieKeys, getSSOSignOutUrl, removeCookie } from "@/api";
import {
CookieKeys,
getSSOSignInUrl,
getSSOSignOutUrl,
removeCookie,
} from "@/api";
import { useConfig } from "@/config";
import { accountStore } from "@/stores";
......@@ -60,6 +65,16 @@ export const Component = () => {
const { pathname } = routerLocation;
const pathnamesHideHeader = ["/waitroom", "/duel"];
const callbackUrl = `${location.origin}/match/`;
const onLogin = () => location.replace(getSSOSignInUrl(callbackUrl));
const onLogout = () => {
removeCookie(CookieKeys.USER);
accountStore.logout();
// 跳转SSO登出
location.replace(getSSOSignOutUrl(callbackUrl));
};
return (
<>
{!pathnamesHideHeader.includes(pathname) && (
......@@ -114,15 +129,8 @@ export const Component = () => {
),
},
{
label: "退出登录",
onClick: () => {
removeCookie(CookieKeys.USER);
accountStore.logout();
// 跳转SSO登出
location.replace(
getSSOSignOutUrl(`${location.origin}/match/}`),
);
},
label: logined ? "退出登录" : "登录萌卡",
onClick: logined ? onLogout : onLogin,
},
].map((x, key) => ({ ...x, key })),
}}
......
......@@ -50,7 +50,7 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => {
const loginViaSSO = () =>
// 跳转回match页
location.replace(getSSOSignInUrl(`${location.origin}/match/}`));
location.replace(getSSOSignInUrl(`${location.origin}/match/`));
const goToMatch = () => navigate("/match");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment