Have auth check if discord user id is an active manager id

This commit is contained in:
Peter 2023-09-09 20:59:45 -04:00
parent 4232dfb4b8
commit a778ddf361
3 changed files with 13 additions and 9 deletions

View File

@ -81,6 +81,7 @@ export default {
name: 'NavBar',
data() {
return {
isAuthenticated: false as Boolean,
userTeam: undefined as Team | undefined,
players: [] as Player[],
searchPlayerName: undefined
@ -281,9 +282,6 @@ export default {
sortedPlayerNames(): string[] {
return this.players.sort((p1, p2) => p2.wara - p1.wara).map(p => p.name)
},
isAuthenticated(): boolean {
return isDiscordAuthenticated()
},
ownerId(): string | undefined {
return getOwnerId()
}
@ -302,7 +300,10 @@ export default {
authenticate()
},
async completeAuthentication(): Promise<void> {
if (this.ownerId) return
if (await isDiscordAuthenticated() || this.isAuthenticated) {
this.isAuthenticated = true
return
}
completeAuthentication()
},

View File

@ -1,3 +1,4 @@
import { fetchActiveTeamByOwnerId } from './teamsService'
import { SITE_URL } from './utilities'
export function authenticate(): void {
@ -9,8 +10,11 @@ export function authenticate(): void {
window.location.href = `https://discord.com/oauth2/authorize?client_id=${clientID}&redirect_uri=${redirectURI}&response_type=token&scope=${scope}`
}
export function isDiscordAuthenticated(): boolean {
return !!getOwnerId()
export async function isDiscordAuthenticated(): Promise<boolean> {
const ownerId: string | undefined = getOwnerId()
if (!ownerId) return false
return !!(await fetchActiveTeamByOwnerId(ownerId))
}
export function getOwnerId(): string | undefined {

View File

@ -308,6 +308,7 @@ export default {
name: "PlayerView",
data() {
return {
isAuthenticated: false as Boolean,
player: undefined as Player | undefined,
last2Decisions: [] as Decision[],
regularSeasonBattingStats: [] as BattingStat[],
@ -330,9 +331,6 @@ export default {
isBatter(): boolean {
return !this.player?.pos_1.includes('P')
},
isAuthenticated(): boolean {
return isDiscordAuthenticated()
},
teamAbbreviation(): string | undefined {
return this.player?.team?.abbrev
},
@ -429,6 +427,7 @@ export default {
},
methods: {
async fetchData(): Promise<void> {
this.isAuthenticated = await isDiscordAuthenticated()
this.player = await this.tryFetchPlayerByNameForAnySeason(this.seasonNumber, this.playerName)
if (!this.player) return