15 lines
536 B
TypeScript
15 lines
536 B
TypeScript
import Auth from '../db/model/auth';
|
|
import { AuthModel, AuthPrivate } from '../db/schema/auth';
|
|
import { sign } from './jwt';
|
|
|
|
export const getAuthenticationBundle = async (username: string, password: string) => {
|
|
const auth = await Auth.findByUsername(username).catch();
|
|
const isAuthenticated = !!auth && (<AuthModel>auth).authenticate(password);
|
|
const record = isAuthenticated ? <string>(<AuthPrivate>auth).record : null;
|
|
const token = sign(record || undefined);
|
|
return {
|
|
record,
|
|
token,
|
|
};
|
|
};
|