🚧 RefreshAuth - refresh tokens now working

ref #12
This commit is contained in:
Philipp Dormann 2020-12-05 13:12:47 +01:00
parent 126799dab9
commit 51addd4a31
1 changed files with 16 additions and 7 deletions

View File

@ -20,7 +20,6 @@ export class RefreshAuth {
} catch (error) {
throw new IllegalJWTError()
}
console.log(decoded["userid"]);
const found_user = await getConnectionManager().get().getRepository(User).findOne({ id: decoded["userid"] });
if (!found_user) {
throw new UserNotFoundError()
@ -28,12 +27,22 @@ export class RefreshAuth {
if (found_user.refreshTokenCount !== decoded["refreshtokencount"]) {
throw new RefreshTokenCountInvalidError()
}
console.log(found_user);
// delete found_user.password;
newAuth.access_token = "ja"
newAuth.access_token_expires_at = 5555555
newAuth.refresh_token = "ja"
newAuth.refresh_token_expires_at = 555555
delete found_user.password;
const timestamp_accesstoken_expiry = Math.floor(Date.now() / 1000) + 5 * 60
delete found_user.password;
newAuth.access_token = jsonwebtoken.sign({
userdetails: found_user,
exp: timestamp_accesstoken_expiry
}, "securekey")
newAuth.access_token_expires_at = timestamp_accesstoken_expiry
//
const timestamp_refresh_expiry = Math.floor(Date.now() / 1000) + 10 * 36000
newAuth.refresh_token = jsonwebtoken.sign({
refreshtokencount: found_user.refreshTokenCount,
userid: found_user.id,
exp: timestamp_refresh_expiry
}, "securekey")
newAuth.refresh_token_expires_at = timestamp_refresh_expiry
return newAuth;
}