mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
21 lines
675 B
TypeScript
21 lines
675 B
TypeScript
import * as bcrypt from 'bcrypt';
|
|
import { AuthApiKeyPrefix } from './Auth.constants';
|
|
|
|
export const hashPassword = (password: string): Promise<string> =>
|
|
new Promise((resolve) => {
|
|
bcrypt.genSalt(10, (error, salt) => {
|
|
bcrypt.hash(password, salt, (err, hash: string) => {
|
|
resolve(hash);
|
|
});
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Extracts and validates an API key from the Authorization header
|
|
* @param {string} authorization - Full authorization header content.
|
|
*/
|
|
export const getAuthApiKey = (authorization: string) => {
|
|
const apiKey = authorization.toLowerCase().replace('bearer ', '').trim();
|
|
return apiKey.startsWith(AuthApiKeyPrefix) ? apiKey : '';
|
|
};
|