Handle reconnect events for websocket errors

This commit is contained in:
Dane Everitt 2020-11-03 20:33:05 -08:00
parent 910a2d7a23
commit c4df534722
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 8 additions and 3 deletions

View file

@ -55,7 +55,7 @@ class NodeJWTService
$builder = (new Builder)->issuedBy(config('app.url')) $builder = (new Builder)->issuedBy(config('app.url'))
->permittedFor($node->getConnectionAddress()) ->permittedFor($node->getConnectionAddress())
->identifiedBy(hash('sha256', $identifiedBy), true) ->identifiedBy(md5($identifiedBy), true)
->issuedAt(CarbonImmutable::now()->getTimestamp()) ->issuedAt(CarbonImmutable::now()->getTimestamp())
->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp()); ->canOnlyBeUsedAfter(CarbonImmutable::now()->subMinutes(5)->getTimestamp());

View file

@ -7,6 +7,11 @@ import { CSSTransition } from 'react-transition-group';
import Spinner from '@/components/elements/Spinner'; import Spinner from '@/components/elements/Spinner';
import tw from 'twin.macro'; import tw from 'twin.macro';
const reconnectErrors = [
'jwt: exp claim is invalid',
'jwt: created too far in past (denylist)',
];
export default () => { export default () => {
let updatingToken = false; let updatingToken = false;
const [ error, setError ] = useState<'connecting' | string>(''); const [ error, setError ] = useState<'connecting' | string>('');
@ -64,7 +69,7 @@ export default () => {
setConnectionState(false); setConnectionState(false);
console.warn('JWT validation error from wings:', error); console.warn('JWT validation error from wings:', error);
if (error === 'jwt: exp claim is invalid') { if (reconnectErrors.find(v => error.toLowerCase().indexOf(v) >= 0)) {
updateToken(uuid, socket); updateToken(uuid, socket);
} else { } else {
setError('There was an error validating the credentials provided for the websocket. Please refresh the page.'); setError('There was an error validating the credentials provided for the websocket. Please refresh the page.');
@ -95,7 +100,7 @@ export default () => {
</p> </p>
</> </>
: :
<p css={tw`ml-2 text-sm text-red-100`}> <p css={tw`ml-2 text-sm text-white`}>
{error} {error}
</p> </p>
} }