Merge pull request #98 from jedmund/fix-auth
Fix various issues with authentication
This commit is contained in:
commit
e6c30c217d
9 changed files with 26 additions and 22 deletions
|
|
@ -234,7 +234,6 @@ const CharacterGrid = (props: Props) => {
|
|||
} skills to your party at once.`
|
||||
setErrorMessage(message)
|
||||
}
|
||||
console.log(error.response.data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import React from 'react'
|
||||
import UncapStar from '~components/UncapStar'
|
||||
|
||||
import './index.scss'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import React from 'react'
|
||||
import classnames from 'classnames'
|
||||
|
||||
import './index.scss'
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -229,12 +230,18 @@ const WeaponGrid = (props: Props) => {
|
|||
id: string,
|
||||
position: number,
|
||||
uncapLevel: number
|
||||
) {
|
||||
if (
|
||||
party.user &&
|
||||
accountState.account.user &&
|
||||
party.user.id === accountState.account.user.id
|
||||
) {
|
||||
memoizeAction(id, position, uncapLevel)
|
||||
|
||||
// Optimistically update UI
|
||||
updateUncapLevel(position, uncapLevel)
|
||||
}
|
||||
}
|
||||
|
||||
const memoizeAction = useCallback(
|
||||
(id: string, position: number, uncapLevel: number) => {
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in a new issue