Merge pull request #98 from jedmund/fix-auth

Fix various issues with authentication
This commit is contained in:
Justin Edmund 2022-12-30 05:25:52 -08:00 committed by GitHub
commit e6c30c217d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 22 deletions

View file

@ -234,7 +234,6 @@ const CharacterGrid = (props: Props) => {
} skills to your party at once.`
setErrorMessage(message)
}
console.log(error.response.data)
})
}
}

View file

@ -78,9 +78,7 @@ const Header = () => {
if (key !== 'language') accountState[key] = resetState[key]
})
if (router.route != '/new') appState.party.editable = false
router.push('/')
router.reload()
return false
}

View file

@ -1,10 +1,11 @@
import React, { useState } from 'react'
import { setCookie } from 'cookies-next'
import Router, { useRouter } from 'next/router'
import { useRouter } from 'next/router'
import { useTranslation } from 'react-i18next'
import axios, { AxiosError, AxiosResponse } from 'axios'
import api from '~utils/api'
import setUserToken from '~utils/setUserToken'
import { accountState } from '~utils/accountState'
import Button from '~components/Button'
@ -86,8 +87,6 @@ const LoginModal = () => {
(error) => error.length > 0 && (valid = false)
)
console.log(errors)
return valid
}
@ -110,8 +109,6 @@ const LoginModal = () => {
.then((id) => fetchUserInfo(id))
.then((infoResponse) => storeUserInfo(infoResponse))
.catch((error: Error | AxiosError) => {
console.log(error)
if (axios.isAxiosError(error)) {
const response = error?.response
if (response && response.data.error === 'invalid_grant') {
@ -141,6 +138,9 @@ const LoginModal = () => {
}
setCookie('account', cookieObj, { path: '/' })
// Set Axios default headers
setUserToken()
}
function storeUserInfo(response: AxiosResponse) {

View file

@ -41,13 +41,11 @@ const Party = (props: Props) => {
// Methods: Creating a new party
async function createParty(extra: boolean = false) {
let body = {
return await api.endpoints.parties.create({
party: {
extra: extra,
},
}
return await api.endpoints.parties.create(body)
})
}
// Methods: Updating the party's details

View file

@ -1,11 +1,11 @@
import React, { useEffect, useState } from 'react'
import Link from 'next/link'
import React, { useState } from 'react'
import { setCookie } from 'cookies-next'
import { useRouter } from 'next/router'
import { Trans, useTranslation } from 'next-i18next'
import { useTranslation } from 'next-i18next'
import { AxiosResponse } from 'axios'
import api from '~utils/api'
import setUserToken from '~utils/setUserToken'
import { accountState } from '~utils/accountState'
import Button from '~components/Button'
@ -95,6 +95,9 @@ const SignupModal = (props: Props) => {
}
setCookie('account', cookieObj, { path: '/' })
// Set Axios default headers
setUserToken()
}
function fetchUserInfo(id: string) {

View file

@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React from 'react'
import UncapStar from '~components/UncapStar'
import './index.scss'

View file

@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React from 'react'
import classnames from 'classnames'
import './index.scss'

View file

@ -18,6 +18,7 @@ import type { SearchableObject } from '~types'
import './index.scss'
import WeaponConflictModal from '~components/WeaponConflictModal'
import Alert from '~components/Alert'
import { accountState } from '~utils/accountState'
// Props
interface Props {
@ -230,10 +231,16 @@ const WeaponGrid = (props: Props) => {
position: number,
uncapLevel: number
) {
memoizeAction(id, position, uncapLevel)
if (
party.user &&
accountState.account.user &&
party.user.id === accountState.account.user.id
) {
memoizeAction(id, position, uncapLevel)
// Optimistically update UI
updateUncapLevel(position, uncapLevel)
// Optimistically update UI
updateUncapLevel(position, uncapLevel)
}
}
const memoizeAction = useCallback(

View file

@ -7,7 +7,6 @@ import Party from '~components/Party'
import { appState } from '~utils/appState'
import { groupWeaponKeys } from '~utils/groupWeaponKeys'
import generateTitle from '~utils/generateTitle'
import organizeRaids from '~utils/organizeRaids'
import setUserToken from '~utils/setUserToken'
import api from '~utils/api'