Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce unnecessary log outs #1386

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions assets/src/components/login/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation, useQuery } from '@apollo/client'
import { ApolloError, useMutation, useQuery } from '@apollo/client'
import { Button, LoopingLogo } from '@pluralsh/design-system'
import { WelcomeHeader } from 'components/utils/WelcomeHeader'
import { useMeQuery } from 'generated/graphql'
import { User, useMeQuery } from 'generated/graphql'
import gql from 'graphql-tag'
import { Div, Flex, Form, P } from 'honorable'
import { RefObject, useEffect, useRef, useState } from 'react'
Expand Down Expand Up @@ -41,16 +41,24 @@ const setInputFocus = (ref: RefObject<any>) => {
})
}

function LoginError({ error }) {
function LoginError({
me,
error,
}: {
me: Nullable<User>
error: ApolloError | undefined
}) {
useEffect(() => {
const to = setTimeout(() => {
wipeToken()
wipeRefreshToken()
window.location = '/login' as any as Location
}, 2000)
if (!error?.networkError && !me) {
const to = setTimeout(() => {
wipeToken()
wipeRefreshToken()
window.location = '/login' as any as Location
}, 2000)

return () => clearTimeout(to)
}, [])
return () => clearTimeout(to)
}
}, [error?.networkError, me])

console.error('Login error:', error)

Expand Down Expand Up @@ -109,7 +117,12 @@ export function EnsureLogin({ children }) {
const loginContextValue = data

if (error || (!loading && !data?.clusterInfo)) {
return <LoginError error={error} />
return (
<LoginError
me={data?.me}
error={error}
/>
)
}

if (!data?.clusterInfo) return null
Expand Down
Loading