Updates as I integrate
This commit is contained in:
@@ -6,6 +6,5 @@
|
||||
.yarnrc.yml
|
||||
babel.config.*
|
||||
jest.config.*
|
||||
src
|
||||
tsconfig*.json
|
||||
tslint.json
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mifi/auth-db",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.10",
|
||||
"author": "mifi (Mike Fitzpatrick)",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -2,15 +2,15 @@ import { Auth, Log } from '..';
|
||||
import { Action } from '../constants/action';
|
||||
import { getLoginToken } from '../utils/getLoginToken';
|
||||
|
||||
export const authenticate = async (username: string, password: string) => {
|
||||
export const authenticate = async (username: string, password: string, includeToken = false) => {
|
||||
const doc = await Auth.findByUsername(username).catch();
|
||||
if (!!doc && (await doc.authenticate(password))) {
|
||||
Log.add(doc.id, Action.AUTHENTICATE);
|
||||
return { ...doc, token: getLoginToken(doc) };
|
||||
return { sub: doc._id, record: doc.record, token: includeToken ? getLoginToken(doc) : undefined };
|
||||
}
|
||||
|
||||
if (doc) {
|
||||
Log.add(doc.id, Action.AUTHENTICATE_FAILURE);
|
||||
Log.add(doc.id, Action.AUTHENTICATE_FAILURE, { ...doc });
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -8,15 +8,18 @@ import { TokenType } from '../../constants/tokens';
|
||||
import { Status } from '../../constants/auth';
|
||||
import { Action } from '../../constants/action';
|
||||
|
||||
type CreateProps = Pick<AuthProps, 'record' | 'username'> & {
|
||||
type CreateProps = Pick<AuthProps, 'username'> & {
|
||||
externalId?: string;
|
||||
handle?: AuthProps['handle'];
|
||||
password?: string;
|
||||
publicKey?: string;
|
||||
record?: AuthProps['record'];
|
||||
};
|
||||
|
||||
export const create = async ({ record, username, externalId, password, publicKey }: CreateProps) => {
|
||||
export const create = async ({ record, username, externalId, handle, password, publicKey }: CreateProps) => {
|
||||
const status = REQUIRE_VERIFICATION ? Status.UNVERIFIED : Status.ACTIVE;
|
||||
const doc = await Auth.create({
|
||||
handle,
|
||||
record,
|
||||
status,
|
||||
username,
|
||||
@@ -55,7 +58,7 @@ export const create = async ({ record, username, externalId, password, publicKey
|
||||
return null;
|
||||
};
|
||||
|
||||
export type Fido2UserProps = Pick<AuthProps, 'record' | 'username'> & { externalId: string; publicKey: string };
|
||||
export type Fido2UserProps = Pick<AuthProps, 'handle' | 'username'> & { externalId: string; publicKey: string };
|
||||
export const createFido2User = (props: Fido2UserProps) => create(props);
|
||||
|
||||
export type LocalUserProps = Pick<AuthProps, 'record' | 'username'> & { password: string };
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { Strategy } from '../../model/strategy';
|
||||
import { AuthDocument } from '../../schema/auth';
|
||||
|
||||
export const readOneByExternalId = async (externalId: string) => Strategy.findOne({ externalId });
|
||||
export const readOneByExternalId = async (externalId: string, populate = false) =>
|
||||
populate
|
||||
? Strategy.findOne({ externalId }).populate<{ parent: AuthDocument }>('parent')
|
||||
: Strategy.findOne({ externalId });
|
||||
|
||||
@@ -7,6 +7,7 @@ import { StrategyDocument } from './strategy';
|
||||
import { verify } from '../utils/password';
|
||||
|
||||
export interface Auth {
|
||||
handle?: string;
|
||||
is2FA?: boolean;
|
||||
record: StringSchemaDefinition;
|
||||
username: string;
|
||||
@@ -35,6 +36,7 @@ export interface AuthModel extends Model<AuthDocument> {
|
||||
|
||||
export const AuthSchema = new Schema<AuthDocument, AuthModel>(
|
||||
{
|
||||
handle: { type: String },
|
||||
is2FA: { type: Boolean, default: false },
|
||||
record: { type: Types.ObjectId, unique: true },
|
||||
status: {
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
"rootDirs": ["./", "src/"],
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": false,
|
||||
"removeComments": true
|
||||
"sourceMap": true,
|
||||
"removeComments": false
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user