Commit 85a585f5 authored by Chunchi Che's avatar Chunchi Che

aucceed logout

parent 21903bc1
Pipeline #23218 passed with stages
in 11 minutes and 18 seconds
......@@ -13,7 +13,8 @@
"stringsUrl":"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf",
"lflistUrl":"https://cdn02.moecube.com:444/ygopro-database/zh-CN/lflist.conf",
"replayUrl":"replay.neos.moe",
"accountUrl":"https://accounts.moecube.com",
"loginUrl":"https://accounts.moecube.com/signin",
"logoutUrl":"https://accounts.moecube.com/signout",
"profileUrl":"https://accounts.moecube.com/profiles",
"streamInterval":20,
"startDelay":1000,
......
......@@ -13,7 +13,8 @@
"stringsUrl":"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf",
"lflistUrl":"https://cdn02.moecube.com:444/ygopro-database/zh-CN/lflist.conf",
"replayUrl":"replay.neos.moe",
"accountUrl":"https://accounts.moecube.com",
"loginUrl":"https://accounts.moecube.com/signin",
"logoutUrl":"https://accounts.moecube.com/signout",
"profileUrl":"https://accounts.moecube.com/profiles",
"streamInterval":20,
"startDelay":1000,
......
/** 构建一个单点登录(Single Sign-On,简称SSO)的URL */
import { useConfig } from "@/config";
const NeosConfig = useConfig();
export function getSSOSignInUrl(callbackUrl: string): string {
const params = new URLSearchParams({
sso: btoa(new URLSearchParams({ return_sso_url: callbackUrl }).toString()),
});
const url = new URL(NeosConfig.loginUrl);
url.search = params.toString();
return url.toString();
}
export function getSSOSignOutUrl(returnUrl: string): string {
const params = new URLSearchParams({
redirect: returnUrl,
});
const url = new URL(NeosConfig.logoutUrl);
url.search = params.toString();
return url.toString();
}
// Collection of APIs provided by MyCard
export * from "./account";
export * from "./match";
......@@ -9,7 +9,7 @@ import {
} from "react-router-dom";
import { useSnapshot } from "valtio";
import { CookieKeys, removeCookie } from "@/api";
import { CookieKeys, getSSOSignOutUrl, removeCookie } from "@/api";
import { useConfig } from "@/config";
import { accountStore } from "@/stores";
......@@ -50,15 +50,15 @@ const HeaderBtn: React.FC<
export const Component = () => {
// 捕获SSO登录
const location = useLocation();
const routerLocation = useLocation();
useEffect(() => {
location.search && handleSSOLogin(location.search);
}, [location.search]);
routerLocation.search && handleSSOLogin(routerLocation.search);
}, [routerLocation.search]);
// 根据是否登录,显示内容
const logined = Boolean(useSnapshot(accountStore).user);
const { pathname } = useLocation();
const { pathname } = routerLocation;
const pathnamesHideHeader = ["/waitroom", "/duel"];
return (
<>
......@@ -118,6 +118,10 @@ export const Component = () => {
onClick: () => {
removeCookie(CookieKeys.USER);
accountStore.logout();
// 跳转SSO登出
location.replace(
getSSOSignOutUrl(`${location.origin}/match/}`),
);
},
},
].map((x, key) => ({ ...x, key })),
......
......@@ -2,6 +2,7 @@ import { RightOutlined } from "@ant-design/icons";
import { useNavigate } from "react-router-dom";
import { useSnapshot } from "valtio";
import { getSSOSignInUrl } from "@/api";
import { useConfig } from "@/config";
import { accountStore } from "@/stores";
import { Background, SpecialButton } from "@/ui/Shared";
......@@ -49,7 +50,7 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => {
const loginViaSSO = () =>
// 跳转回match页
location.replace(getSSOUrl(`${location.origin}/match/}`));
location.replace(getSSOSignInUrl(`${location.origin}/match/}`));
const goToMatch = () => navigate("/match");
......@@ -60,15 +61,3 @@ const LoginBtn: React.FC<{ logined: boolean }> = ({ logined }) => {
</SpecialButton>
);
};
/** 构建一个单点登录(Single Sign-On,简称SSO)的URL */
function getSSOUrl(callbackUrl: string): string {
const params = new URLSearchParams({
sso: btoa(new URLSearchParams({ return_sso_url: callbackUrl }).toString()),
});
const url = new URL(NeosConfig.accountUrl);
url.search = params.toString();
return url.toString();
}
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