mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-23 22:46:35 +01:00
fix: invalid token redirect and error handling
This commit is contained in:
parent
ca1c7292a4
commit
194dafb940
2 changed files with 26 additions and 7 deletions
|
@ -1,5 +1,11 @@
|
|||
import { useGetNodeInfoQuery } from '../../src/graphql/queries/__generated__/getNodeInfo.generated';
|
||||
import { getVersion } from '../../src/utils/version';
|
||||
import getConfig from 'next/config';
|
||||
import { useEffect } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
const { publicRuntimeConfig } = getConfig();
|
||||
const { logoutUrl, basePath } = publicRuntimeConfig;
|
||||
|
||||
type StatusState = {
|
||||
alias: string;
|
||||
|
@ -34,6 +40,12 @@ const initialState: StatusState = {
|
|||
export const useNodeInfo = (): StatusState => {
|
||||
const { data, loading, error } = useGetNodeInfoQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if (!error) return;
|
||||
toast.error(`Unable to connect to node`);
|
||||
window.location.href = logoutUrl || `${basePath}/login`;
|
||||
}, [error]);
|
||||
|
||||
if (!data?.getNodeInfo || loading || error) {
|
||||
return initialState;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,30 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
import { Logger } from 'winston';
|
||||
import { AccountsService } from '../accounts/accounts.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthenticationService {
|
||||
constructor(
|
||||
private readonly jwtService: JwtService,
|
||||
private accountsService: AccountsService
|
||||
private accountsService: AccountsService,
|
||||
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger
|
||||
) {}
|
||||
|
||||
public async getUserFromAuthToken(token: string) {
|
||||
const payload = this.jwtService.verify(token);
|
||||
try {
|
||||
const payload = this.jwtService.verify(token);
|
||||
|
||||
if (payload.sub) {
|
||||
const account = this.accountsService.getAccount(payload.sub);
|
||||
if (payload.sub) {
|
||||
const account = this.accountsService.getAccount(payload.sub);
|
||||
|
||||
if (account) {
|
||||
return payload.sub;
|
||||
if (account) {
|
||||
return payload.sub;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error('Invalid token for authentication');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue