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 7f5765aaaa
All checks were successful
continuous-integration/drone/push Build is passing
Finally have prettier and linting maybe working
2023-05-02 10:54:45 -04:00

15 lines
558 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 : null;
const token = isAuthenticated ? (auth as AuthModel).getToken() : sign();
return {
record,
token,
};
};