|
|
@@ -139,82 +139,14 @@ const submitClick = async () => {
|
|
|
}
|
|
|
|
|
|
const params: any = router.currentRoute.value.query;
|
|
|
- // console.log(params, 999);
|
|
|
if ("redirect" in params && params.redirect) {
|
|
|
- const rawRedirect = String(params.redirect);
|
|
|
- let decoded = rawRedirect;
|
|
|
- try {
|
|
|
- decoded = decodeURIComponent(rawRedirect);
|
|
|
- } catch {
|
|
|
- try {
|
|
|
- decoded = decodeURI(rawRedirect);
|
|
|
- } catch {}
|
|
|
- }
|
|
|
- let url: URL;
|
|
|
- try {
|
|
|
- url = decoded.startsWith("http://") || decoded.startsWith("https://")
|
|
|
- ? new URL(decoded)
|
|
|
- : new URL(decoded, window.location.origin);
|
|
|
- } catch (e) {
|
|
|
- console.warn("Invalid redirect URL, fallback to dispatch:", decoded, e);
|
|
|
- router.replace({ name: RouteName.dispatch });
|
|
|
- return;
|
|
|
- }
|
|
|
- const isAbsolute = /^https?:\/\//.test(decoded);
|
|
|
- const isInternal = !isAbsolute || url.origin === window.location.origin;
|
|
|
-
|
|
|
- // remove token from appropriate place
|
|
|
- window.localStorage.setItem('token', user.value.token);
|
|
|
- if (isInternal) {
|
|
|
- let targetPath = '';
|
|
|
- if (url.hash) {
|
|
|
- const hashStr = url.hash.slice(1); // remove leading '#'
|
|
|
- const qIndex = hashStr.indexOf('?');
|
|
|
- if (qIndex > -1) {
|
|
|
- const basePath = hashStr.slice(0, qIndex);
|
|
|
- const queryStr = hashStr.slice(qIndex + 1);
|
|
|
- const usp = new URLSearchParams(queryStr);
|
|
|
- usp.delete('token');
|
|
|
- const qs = usp.toString();
|
|
|
- targetPath = qs ? `${basePath}?${qs}` : basePath;
|
|
|
- } else {
|
|
|
- targetPath = hashStr;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // Fallback: when redirect contains '%23' in pathname (encoded '#'), treat as hash route
|
|
|
- if (url.pathname.includes('%23')) {
|
|
|
- const idx = url.pathname.indexOf('%23');
|
|
|
- const after = url.pathname.slice(idx + 3); // content after '%23'
|
|
|
- const qIndex = after.indexOf('?');
|
|
|
- if (qIndex > -1) {
|
|
|
- const basePath = after.slice(0, qIndex);
|
|
|
- const queryStr = after.slice(qIndex + 1);
|
|
|
- const usp = new URLSearchParams(queryStr);
|
|
|
- usp.delete('token');
|
|
|
- const qs = usp.toString();
|
|
|
- targetPath = qs ? `${basePath}?${qs}` : basePath;
|
|
|
- } else {
|
|
|
- targetPath = after;
|
|
|
- }
|
|
|
- } else {
|
|
|
- const usp = new URLSearchParams(url.search);
|
|
|
- usp.delete('token');
|
|
|
- const qs = usp.toString();
|
|
|
- const pathName = url.pathname;
|
|
|
- targetPath = qs ? `${pathName}?${qs}` : pathName;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!targetPath.startsWith('/')) targetPath = '/' + targetPath;
|
|
|
- console.log('Internal redirect to', targetPath);
|
|
|
- router.replace(targetPath);
|
|
|
- } else {
|
|
|
- url.searchParams.delete("token");
|
|
|
- console.log('External redirect to', url.toString());
|
|
|
- window.location.replace(url.toString());
|
|
|
- }
|
|
|
+ const url = new URL(decodeURIComponent(params.redirect as string));
|
|
|
+ url.searchParams.delete("token");
|
|
|
+ // url.searchParams.append("token", user.value.token);
|
|
|
+ window.localStorage.setItem('token', user.value.token)
|
|
|
+ window.location.replace(url);
|
|
|
} else {
|
|
|
- // router.replace({ name: RouteName.scene });
|
|
|
- router.replace({ name: RouteName.dispatch });
|
|
|
+ router.replace({ name: RouteName.example });
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.error(e);
|