This repository has been archived on 2023-05-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
auth/lib/utils/auth.ts
mifi adb3866700
Some checks failed
continuous-integration/drone/push Build is failing
linty fresh(er)
2023-05-02 20:23:19 -04:00

15 lines
536 B
TypeScript

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