Commit 147d139f authored by nanahira's avatar nanahira

add loginUser thing

parent e4b54a0a
Pipeline #16062 passed with stages
in 6 minutes and 25 seconds
......@@ -13,10 +13,11 @@ export class AuthGuard implements CanActivateChild {
return true;
}
const token = state.root.queryParamMap.get('sso') || new URL(location.href).searchParams.get('sso') || localStorage.getItem('login');
const tokenFromSSO = state.root.queryParamMap.get('sso') || new URL(location.href).searchParams.get('sso');
const token = tokenFromSSO || localStorage.getItem('login');
if (token) {
this.login.callback(token);
this.login.callback(token, !!tokenFromSSO);
return true;
} else {
location.replace(this.login.login());
......
......@@ -56,7 +56,7 @@ export class LoginService {
return url.toString();
}
callback(token: string) {
callback(token: string, isNewLogin: boolean) {
this.token = token;
this.user = <any>fromPairs(Array.from(new URLSearchParams(Buffer.from(token, 'base64').toString())));
Raven.setUserContext({
......@@ -67,7 +67,11 @@ export class LoginService {
localStorage.setItem('login', token);
if (window.ygopro) {
try {
window.ygopro.updateUser(this.user.username, this.user.avatar_url, this.user.email);
if(isNewLogin && window.ygopro.loginUser) {
window.ygopro.loginUser(this.user, null);
} else {
window.ygopro.updateUser(this.user.username, this.user.avatar_url, this.user.email);
}
} catch (error) {
console.error(error);
}
......
......@@ -21,6 +21,7 @@ export interface User {
moderator: boolean;
name: string;
username: string;
token: string;
}
export interface Room {
......
......@@ -16,6 +16,7 @@ interface Window {
backHome(): void;
share(text: string): void
updateUser(name: string, avatar: string, status: string): void;
loginUser(user: any, exception: any): void;
readFile(path: string): string;
writeFile(path: string, data: string): string;
......
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