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.`
|
} skills to your party at once.`
|
||||||
setErrorMessage(message)
|
setErrorMessage(message)
|
||||||
}
|
}
|
||||||
console.log(error.response.data)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,7 @@ const Header = () => {
|
||||||
if (key !== 'language') accountState[key] = resetState[key]
|
if (key !== 'language') accountState[key] = resetState[key]
|
||||||
})
|
})
|
||||||
|
|
||||||
if (router.route != '/new') appState.party.editable = false
|
router.reload()
|
||||||
|
|
||||||
router.push('/')
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { setCookie } from 'cookies-next'
|
import { setCookie } from 'cookies-next'
|
||||||
import Router, { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import axios, { AxiosError, AxiosResponse } from 'axios'
|
import axios, { AxiosError, AxiosResponse } from 'axios'
|
||||||
|
|
||||||
import api from '~utils/api'
|
import api from '~utils/api'
|
||||||
|
import setUserToken from '~utils/setUserToken'
|
||||||
import { accountState } from '~utils/accountState'
|
import { accountState } from '~utils/accountState'
|
||||||
|
|
||||||
import Button from '~components/Button'
|
import Button from '~components/Button'
|
||||||
|
|
@ -86,8 +87,6 @@ const LoginModal = () => {
|
||||||
(error) => error.length > 0 && (valid = false)
|
(error) => error.length > 0 && (valid = false)
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log(errors)
|
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,8 +109,6 @@ const LoginModal = () => {
|
||||||
.then((id) => fetchUserInfo(id))
|
.then((id) => fetchUserInfo(id))
|
||||||
.then((infoResponse) => storeUserInfo(infoResponse))
|
.then((infoResponse) => storeUserInfo(infoResponse))
|
||||||
.catch((error: Error | AxiosError) => {
|
.catch((error: Error | AxiosError) => {
|
||||||
console.log(error)
|
|
||||||
|
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
const response = error?.response
|
const response = error?.response
|
||||||
if (response && response.data.error === 'invalid_grant') {
|
if (response && response.data.error === 'invalid_grant') {
|
||||||
|
|
@ -141,6 +138,9 @@ const LoginModal = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
setCookie('account', cookieObj, { path: '/' })
|
setCookie('account', cookieObj, { path: '/' })
|
||||||
|
|
||||||
|
// Set Axios default headers
|
||||||
|
setUserToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeUserInfo(response: AxiosResponse) {
|
function storeUserInfo(response: AxiosResponse) {
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,11 @@ const Party = (props: Props) => {
|
||||||
|
|
||||||
// Methods: Creating a new party
|
// Methods: Creating a new party
|
||||||
async function createParty(extra: boolean = false) {
|
async function createParty(extra: boolean = false) {
|
||||||
let body = {
|
return await api.endpoints.parties.create({
|
||||||
party: {
|
party: {
|
||||||
extra: extra,
|
extra: extra,
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
return await api.endpoints.parties.create(body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methods: Updating the party's details
|
// Methods: Updating the party's details
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import React, { useEffect, useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import Link from 'next/link'
|
|
||||||
import { setCookie } from 'cookies-next'
|
import { setCookie } from 'cookies-next'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { Trans, useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
import { AxiosResponse } from 'axios'
|
import { AxiosResponse } from 'axios'
|
||||||
|
|
||||||
import api from '~utils/api'
|
import api from '~utils/api'
|
||||||
|
import setUserToken from '~utils/setUserToken'
|
||||||
import { accountState } from '~utils/accountState'
|
import { accountState } from '~utils/accountState'
|
||||||
|
|
||||||
import Button from '~components/Button'
|
import Button from '~components/Button'
|
||||||
|
|
@ -95,6 +95,9 @@ const SignupModal = (props: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
setCookie('account', cookieObj, { path: '/' })
|
setCookie('account', cookieObj, { path: '/' })
|
||||||
|
|
||||||
|
// Set Axios default headers
|
||||||
|
setUserToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchUserInfo(id: string) {
|
function fetchUserInfo(id: string) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect } from 'react'
|
import React from 'react'
|
||||||
import UncapStar from '~components/UncapStar'
|
import UncapStar from '~components/UncapStar'
|
||||||
|
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect } from 'react'
|
import React from 'react'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import type { SearchableObject } from '~types'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
import WeaponConflictModal from '~components/WeaponConflictModal'
|
import WeaponConflictModal from '~components/WeaponConflictModal'
|
||||||
import Alert from '~components/Alert'
|
import Alert from '~components/Alert'
|
||||||
|
import { accountState } from '~utils/accountState'
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -230,10 +231,16 @@ const WeaponGrid = (props: Props) => {
|
||||||
position: number,
|
position: number,
|
||||||
uncapLevel: 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
|
// Optimistically update UI
|
||||||
updateUncapLevel(position, uncapLevel)
|
updateUncapLevel(position, uncapLevel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const memoizeAction = useCallback(
|
const memoizeAction = useCallback(
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import Party from '~components/Party'
|
||||||
|
|
||||||
import { appState } from '~utils/appState'
|
import { appState } from '~utils/appState'
|
||||||
import { groupWeaponKeys } from '~utils/groupWeaponKeys'
|
import { groupWeaponKeys } from '~utils/groupWeaponKeys'
|
||||||
import generateTitle from '~utils/generateTitle'
|
|
||||||
import organizeRaids from '~utils/organizeRaids'
|
import organizeRaids from '~utils/organizeRaids'
|
||||||
import setUserToken from '~utils/setUserToken'
|
import setUserToken from '~utils/setUserToken'
|
||||||
import api from '~utils/api'
|
import api from '~utils/api'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue