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
2023-05-02 01:14:23 -04:00

15 lines
572 B
TypeScript

import Auth from '../model/auth';
import { AuthDocument, 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 token = isAuthenticated ? (auth as AuthModel).getToken() : sign();
const record = isAuthenticated ? (auth as AuthPrivate).record : null;
return {
record,
token,
};
};