fix login flow
This commit is contained in:
parent
8d90935e7d
commit
7cba6fc7ef
@ -50,6 +50,7 @@ class Player:
|
||||
if r.status_code == 200:
|
||||
res = r.json()
|
||||
self.avatar = f'https://cdn.discordapp.com/avatars/{res["id"]}/{res["avatar"]}.png'
|
||||
if self.game:
|
||||
self.sio.emit('chat_message', room=self.game.name, data=f'_change_username|{self.name}|{res["username"]}')
|
||||
self.name = res['username']
|
||||
self.discord_id = res['id']
|
||||
|
@ -96,7 +96,7 @@ def set_username(sid, username):
|
||||
username = username["name"]
|
||||
print(f'{sid} changed username to {username}')
|
||||
prev = ses.name
|
||||
if len([p for p in ses.game.players if p.name == username]) > 0:
|
||||
if ses.game and len([p for p in ses.game.players if p.name == username]) > 0:
|
||||
ses.name = f"{username}_{random.randint(0,100)}"
|
||||
else:
|
||||
ses.name = username
|
||||
|
@ -115,7 +115,7 @@ export default {
|
||||
discord_auth_succ(data) {
|
||||
if (data.access_token) {
|
||||
localStorage.setItem('discord_token', data.access_token)
|
||||
this.$$router.push({path:'/'})
|
||||
this.login()
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -157,13 +157,7 @@ export default {
|
||||
init() {
|
||||
location.reload();
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (this.$route.query.code) {
|
||||
this.$socket.emit('discord_auth', {code:this.$route.query.code, origin:window.location.origin})
|
||||
}
|
||||
else if (localStorage.getItem('discord_token')) {
|
||||
//get username from discord
|
||||
login() {
|
||||
fetch('https://discordapp.com/api/users/@me', {
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + localStorage.getItem('discord_token')
|
||||
@ -179,8 +173,17 @@ export default {
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
localStorage.removeItem('discord_token')
|
||||
this.$router.replace({query: []})
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (localStorage.getItem('discord_token')) {
|
||||
this.login()
|
||||
} else if (this.$route.query.code) {
|
||||
this.$socket.emit('discord_auth', {code:this.$route.query.code, origin:window.location.origin})
|
||||
this.$router.replace({query: []})
|
||||
}
|
||||
this.randomTip = `tip_${1+Math.floor(Math.random() * 8)}`
|
||||
if (localStorage.getItem('username'))
|
||||
this.username = localStorage.getItem('username')
|
||||
|
Loading…
Reference in New Issue
Block a user