Compare commits
2 commits
develop
...
fix-consol
Author | SHA1 | Date | |
---|---|---|---|
f770876de5 | |||
06221e6301 |
|
@ -31,41 +31,47 @@ class ConnectionManager {
|
||||||
|
|
||||||
const room = new Room(window.location.pathname + window.location.hash);
|
const room = new Room(window.location.pathname + window.location.hash);
|
||||||
return Promise.resolve(room);
|
return Promise.resolve(room);
|
||||||
} else if (connexionType === GameConnexionTypes.anonymous || connexionType === GameConnexionTypes.empty) {
|
} else {
|
||||||
const localUser = localUserStore.getLocalUser();
|
//if connexion anonymous, remove local token
|
||||||
|
if(connexionType !== GameConnexionTypes.organization) {
|
||||||
|
localUserStore.removeUser();
|
||||||
|
}
|
||||||
|
if (connexionType === GameConnexionTypes.anonymous || connexionType === GameConnexionTypes.empty) {
|
||||||
|
const localUser = localUserStore.getLocalUser();
|
||||||
|
|
||||||
if (localUser && localUser.jwtToken && localUser.uuid && localUser.textures) {
|
if (localUser && localUser.jwtToken && localUser.uuid && localUser.textures) {
|
||||||
this.localUser = localUser;
|
this.localUser = localUser;
|
||||||
try {
|
try {
|
||||||
await this.verifyToken(localUser.jwtToken);
|
await this.verifyToken(localUser.jwtToken);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
// If the token is invalid, let's generate an anonymous one.
|
// If the token is invalid, let's generate an anonymous one.
|
||||||
console.error('JWT token invalid. Did it expire? Login anonymously instead.');
|
console.error('JWT token invalid. Did it expire? Login anonymously instead.');
|
||||||
|
await this.anonymousLogin();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
await this.anonymousLogin();
|
await this.anonymousLogin();
|
||||||
}
|
}
|
||||||
} else {
|
let roomId: string
|
||||||
await this.anonymousLogin();
|
if (connexionType === GameConnexionTypes.empty) {
|
||||||
}
|
const defaultMapUrl = window.location.host.replace('play.', 'maps.') + URL_ROOM_STARTED;
|
||||||
let roomId: string
|
roomId = urlManager.editUrlForRoom(defaultMapUrl, null, null);
|
||||||
if (connexionType === GameConnexionTypes.empty) {
|
} else {
|
||||||
const defaultMapUrl = window.location.host.replace('play.', 'maps.') + URL_ROOM_STARTED;
|
roomId = window.location.pathname + window.location.hash;
|
||||||
roomId = urlManager.editUrlForRoom(defaultMapUrl, null, null);
|
}
|
||||||
} else {
|
const room = new Room(roomId);
|
||||||
roomId = window.location.pathname + window.location.hash;
|
|
||||||
}
|
|
||||||
const room = new Room(roomId);
|
|
||||||
return Promise.resolve(room);
|
|
||||||
} else if (connexionType == GameConnexionTypes.organization) {
|
|
||||||
const localUser = localUserStore.getLocalUser();
|
|
||||||
|
|
||||||
if (localUser) {
|
|
||||||
this.localUser = localUser;
|
|
||||||
await this.verifyToken(localUser.jwtToken);
|
|
||||||
const room = new Room(window.location.pathname + window.location.hash);
|
|
||||||
return Promise.resolve(room);
|
return Promise.resolve(room);
|
||||||
} else {
|
} else if (connexionType == GameConnexionTypes.organization) {
|
||||||
//todo: find some kind of fallback?
|
const localUser = localUserStore.getLocalUser();
|
||||||
return Promise.reject('Could not find a user in localstorage');
|
|
||||||
|
if (localUser) {
|
||||||
|
this.localUser = localUser;
|
||||||
|
await this.verifyToken(localUser.jwtToken);
|
||||||
|
const room = new Room(window.location.pathname + window.location.hash);
|
||||||
|
return Promise.resolve(room);
|
||||||
|
} else {
|
||||||
|
//todo: find some kind of fallback?
|
||||||
|
return Promise.reject('Could not find a user in localstorage');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,11 @@ class LocalUserStore {
|
||||||
saveUser(localUser: LocalUser) {
|
saveUser(localUser: LocalUser) {
|
||||||
localStorage.setItem('localUser', JSON.stringify(localUser));
|
localStorage.setItem('localUser', JSON.stringify(localUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeUser() {
|
||||||
|
localStorage.removeItem('localUser');
|
||||||
|
}
|
||||||
|
|
||||||
getLocalUser(): LocalUser|null {
|
getLocalUser(): LocalUser|null {
|
||||||
const data = localStorage.getItem('localUser');
|
const data = localStorage.getItem('localUser');
|
||||||
return data ? JSON.parse(data) : null;
|
return data ? JSON.parse(data) : null;
|
||||||
|
|
Loading…
Reference in a new issue