parent
093f6f5f78
commit
c0c95056bf
@ -98,4 +98,15 @@ export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableEr
|
|||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
message = "user was not found or refresh token count was invalid"
|
message = "user was not found or refresh token count was invalid"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error to thow when refresh token count was invalid
|
||||||
|
*/
|
||||||
|
export class RefreshTokenCountInvalidError extends NotAcceptableError {
|
||||||
|
@IsString()
|
||||||
|
name = "RefreshTokenCountInvalidError"
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
message = "refresh token count was invalid"
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import * as jsonwebtoken from 'jsonwebtoken';
|
import * as jsonwebtoken from 'jsonwebtoken';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import { IllegalJWTError, JwtNotProvidedError, UserNotFoundOrRefreshTokenCountInvalidError } from '../../errors/AuthError';
|
import { IllegalJWTError, JwtNotProvidedError, RefreshTokenCountInvalidError, UserNotFoundError } from '../../errors/AuthError';
|
||||||
import { Auth } from '../entities/Auth';
|
import { Auth } from '../entities/Auth';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
|
|
||||||
@ -20,16 +20,18 @@ export class RefreshAuth {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new IllegalJWTError()
|
throw new IllegalJWTError()
|
||||||
}
|
}
|
||||||
const found_users = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"], refreshTokenCount: decoded["refreshtokencount"] });
|
|
||||||
if (!found_users) {
|
|
||||||
throw new UserNotFoundOrRefreshTokenCountInvalidError()
|
|
||||||
} else {
|
|
||||||
const found_user = found_users[0]
|
const found_user = found_users[0]
|
||||||
delete found_user.password;
|
delete found_user.password;
|
||||||
newAuth.access_token = "ja"
|
newAuth.access_token = "ja"
|
||||||
newAuth.access_token_expires_at = 5555555
|
newAuth.access_token_expires_at = 5555555
|
||||||
newAuth.refresh_token = "ja"
|
newAuth.refresh_token = "ja"
|
||||||
newAuth.refresh_token_expires_at = 555555
|
newAuth.refresh_token_expires_at = 555555
|
||||||
|
const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] });
|
||||||
|
if (!found_user) {
|
||||||
|
throw new UserNotFoundError()
|
||||||
|
}
|
||||||
|
if (found_user.refreshTokenCount !== decoded["refreshtokencount"]) {
|
||||||
|
throw new RefreshTokenCountInvalidError()
|
||||||
}
|
}
|
||||||
return newAuth;
|
return newAuth;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user