omnivore/packages/api/src/utils/auth.ts
Hongbo Wu 2ebdaba780
add generate api key api and test (#392)
* add generate api key api and test

* test if user can make api call with the api key
2022-04-12 12:11:45 +08:00

16 lines
465 B
TypeScript

import * as bcrypt from 'bcryptjs'
import * as jwt from 'jsonwebtoken'
import { env } from '../env'
import { Claims } from '../resolvers/types'
export const hashPassword = (password: string) => {
return bcrypt.hashSync(password, 10)
}
export const comparePassword = (password: string, hash: string) => {
return bcrypt.compareSync(password, hash)
}
export const generateApiKey = (claims: Claims): string => {
return jwt.sign(claims, env.server.jwtSecret)
}