mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
fix: typescript errors
This commit is contained in:
@@ -234,9 +234,10 @@ const verifyAuthCode = async (
|
|||||||
jwt.verify(code, process.secrets.AUTH_CODE_SECRET, (err, data) => {
|
jwt.verify(code, process.secrets.AUTH_CODE_SECRET, (err, data) => {
|
||||||
if (err) return resolve(undefined)
|
if (err) return resolve(undefined)
|
||||||
|
|
||||||
|
const payload = data as InfoJWT
|
||||||
const clientInfo: InfoJWT = {
|
const clientInfo: InfoJWT = {
|
||||||
clientId: data?.clientId,
|
clientId: payload?.clientId,
|
||||||
userId: data?.userId
|
userId: payload?.userId
|
||||||
}
|
}
|
||||||
if (clientInfo.clientId === clientId) {
|
if (clientInfo.clientId === clientId) {
|
||||||
return resolve(clientInfo)
|
return resolve(clientInfo)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const login = async (
|
|||||||
const rateLimiter = RateLimiter.getInstance()
|
const rateLimiter = RateLimiter.getInstance()
|
||||||
|
|
||||||
if (!validPass) {
|
if (!validPass) {
|
||||||
const retrySecs = await rateLimiter.consume(req.ip, user?.username)
|
const retrySecs = await rateLimiter.consume(req.ip || 'unknown', user?.username)
|
||||||
if (retrySecs > 0) throw errors.tooManyRequests(retrySecs)
|
if (retrySecs > 0) throw errors.tooManyRequests(retrySecs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ const login = async (
|
|||||||
if (!validPass) throw errors.invalidPassword
|
if (!validPass) throw errors.invalidPassword
|
||||||
|
|
||||||
// Reset on successful authorization
|
// Reset on successful authorization
|
||||||
rateLimiter.resetOnSuccess(req.ip, user.username)
|
rateLimiter.resetOnSuccess(req.ip || 'unknown', user.username)
|
||||||
|
|
||||||
req.session.loggedIn = true
|
req.session.loggedIn = true
|
||||||
req.session.user = {
|
req.session.user = {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { convertSecondsToHms } from '@sasjs/utils'
|
|||||||
import { RateLimiter } from '../utils'
|
import { RateLimiter } from '../utils'
|
||||||
|
|
||||||
export const bruteForceProtection: RequestHandler = async (req, res, next) => {
|
export const bruteForceProtection: RequestHandler = async (req, res, next) => {
|
||||||
const ip = req.ip
|
const ip = req.ip || 'unknown'
|
||||||
const username = req.body.username
|
const username = req.body.username
|
||||||
|
|
||||||
const rateLimiter = RateLimiter.getInstance()
|
const rateLimiter = RateLimiter.getInstance()
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ const performLogin = async (
|
|||||||
.set('x-xsrf-token', csrfToken)
|
.set('x-xsrf-token', csrfToken)
|
||||||
.send(credentials)
|
.send(credentials)
|
||||||
|
|
||||||
return { authCookies: header['set-cookie'].join() }
|
return { authCookies: header['set-cookie']?.join() || '' }
|
||||||
}
|
}
|
||||||
|
|
||||||
const extractCSRF = (text: string) =>
|
const extractCSRF = (text: string) =>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
import User from '../model/User'
|
import User from '../model/User'
|
||||||
|
import { InfoJWT } from '../types/InfoJWT'
|
||||||
|
|
||||||
const isValidToken = async (
|
const isValidToken = async (
|
||||||
token: string,
|
token: string,
|
||||||
@@ -11,7 +12,8 @@ const isValidToken = async (
|
|||||||
jwt.verify(token, key, (err, decoded) => {
|
jwt.verify(token, key, (err, decoded) => {
|
||||||
if (err) return reject(false)
|
if (err) return reject(false)
|
||||||
|
|
||||||
if (decoded?.userId === userId && decoded?.clientId === clientId) {
|
const payload = decoded as InfoJWT
|
||||||
|
if (payload?.userId === userId && payload?.clientId === clientId) {
|
||||||
return resolve(true)
|
return resolve(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user