fix architecture and write new tests
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import bcrypt from 'bcryptjs'
|
||||
import jwt from 'jsonwebtoken'
|
||||
import { prisma } from '../../lib/prisma'
|
||||
|
||||
const JWT_SECRET = process.env.JWT_SECRET ?? 'test-secret'
|
||||
import { signActorToken } from '../../security/tokens'
|
||||
|
||||
let counter = 0
|
||||
function uid() {
|
||||
@@ -215,28 +213,16 @@ export async function createRenterNotification(
|
||||
})
|
||||
}
|
||||
|
||||
export function signEmployeeToken(employeeId: string, companyId: string, role: string = 'OWNER') {
|
||||
return jwt.sign(
|
||||
{ sub: employeeId, companyId, role, type: 'employee' },
|
||||
JWT_SECRET,
|
||||
{ expiresIn: '1h' },
|
||||
)
|
||||
export function signEmployeeToken(employeeId: string, _companyId: string, _role: string = 'OWNER') {
|
||||
return signActorToken(employeeId, 'employee', { expiresIn: '1h' })
|
||||
}
|
||||
|
||||
export function signAdminToken(adminId: string) {
|
||||
return jwt.sign(
|
||||
{ sub: adminId, type: 'admin' },
|
||||
JWT_SECRET,
|
||||
{ expiresIn: '1h' },
|
||||
)
|
||||
return signActorToken(adminId, 'admin', { expiresIn: '1h', last2faAt: Date.now() })
|
||||
}
|
||||
|
||||
export function signRenterToken(renterId: string) {
|
||||
return jwt.sign(
|
||||
{ sub: renterId, type: 'renter' },
|
||||
JWT_SECRET,
|
||||
{ expiresIn: '1h' },
|
||||
)
|
||||
return signActorToken(renterId, 'renter', { expiresIn: '1h' })
|
||||
}
|
||||
|
||||
export function authHeader(token: string) {
|
||||
|
||||
Reference in New Issue
Block a user