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 { ...@@ -14,9 +14,9 @@ export function getSSOSignInUrl(callbackUrl: string): string {
return url.toString(); return url.toString();
} }
export function getSSOSignOutUrl(returnUrl: string): string { export function getSSOSignOutUrl(callbackUrl: string): string {
const params = new URLSearchParams({ const params = new URLSearchParams({
redirect: returnUrl, redirect: callbackUrl,
}); });
const url = new URL(NeosConfig.logoutUrl); const url = new URL(NeosConfig.logoutUrl);
......
...@@ -9,7 +9,12 @@ import { ...@@ -9,7 +9,12 @@ import {
} from "react-router-dom"; } from "react-router-dom";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { CookieKeys, getSSOSignOutUrl, removeCookie } from "@/api"; import {
CookieKeys,
getSSOSignInUrl,
getSSOSignOutUrl,
removeCookie,
} from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { accountStore } from "@/stores"; import { accountStore } from "@/stores";
...@@ -60,6 +65,16 @@ export const Component = () => { ...@@ -60,6 +65,16 @@ export const Component = () => {
const { pathname } = routerLocation; const { pathname } = routerLocation;
const pathnamesHideHeader = ["/waitroom", "/duel"]; 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 ( return (
<> <>
{!pathnamesHideHeader.includes(pathname) && ( {!pathnamesHideHeader.includes(pathname) && (
...@@ -114,15 +129,8 @@ export const Component = () => { ...@@ -114,15 +129,8 @@ export const Component = () => {
), ),
}, },
{ {
label: "退出登录", label: logined ? "退出登录" : "登录萌卡",
onClick: () => { onClick: logined ? onLogout : onLogin,
removeCookie(CookieKeys.USER);
accountStore.logout();
// 跳转SSO登出
location.replace(
getSSOSignOutUrl(`${location.origin}/match/}`),
);
},
}, },
].map((x, key) => ({ ...x, key })), ].map((x, key) => ({ ...x, key })),
}} }}
......
...@@ -50,7 +50,7 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => { ...@@ -50,7 +50,7 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => {
const loginViaSSO = () => const loginViaSSO = () =>
// 跳转回match页 // 跳转回match页
location.replace(getSSOSignInUrl(`${location.origin}/match/}`)); location.replace(getSSOSignInUrl(`${location.origin}/match/`));
const goToMatch = () => navigate("/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