@krypton-org/krypton-auth
Version:
Express authentication middleware, using GraphQL and JSON Web Tokens.
88 lines • 3.01 kB
JavaScript
;
/**
* Module returning the Mongoose schema merging the default one with the fields provided by the package user through the `extendedSchema` property.
* @module model/UserSchema
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = __importDefault(require("../config"));
// Default Mongoose schema.
const basicSchema = {
email: {
isPublic: false,
lowercase: true,
maxlength: 256,
required: true,
type: String,
unique: true,
validate: {
message: () => 'This email address is not valid.',
validator: v => /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(v),
},
},
email_verified: {
default: false,
isPublic: true,
isUneditable: true,
required: true,
type: Boolean,
},
password: {
isInternal: true,
isPublic: false,
required: true,
type: String,
},
passwordRecoveryRequestDate: {
isInternal: true,
isPublic: false,
type: Date,
},
passwordRecoveryToken: {
isInternal: true,
isPublic: false,
type: String,
},
passwordSalt: {
isInternal: true,
isPublic: false,
required: true,
type: String,
},
refreshToken: {
isInternal: true,
isPublic: false,
type: String,
},
refreshTokenExpiryDate: {
isInternal: true,
isPublic: false,
type: Date,
},
verificationToken: {
isInternal: true,
isPublic: false,
type: String,
},
};
/** Mongoose User schema: built merging the default User schema with the fields provided by the package user through the `extendedSchema` property. */
const UserSchema = Object.assign(Object.assign({}, basicSchema), config_1.default.extendedSchema);
exports.UserSchema = UserSchema;
/**
* List of private fields. Fields that are private to users (like email address) and not shared with the public queries (`userById`, `userMany`...) of the API .
*/
const privateFields = Object.keys(UserSchema).filter(x => !UserSchema[x].isPublic);
exports.privateFields = privateFields;
/**
* List of internal fields. Fields that are internal to the system, nobody can access it (like user password hash and salt).
*/
const internalFields = Object.keys(UserSchema).filter(x => UserSchema[x].isInternal);
exports.internalFields = internalFields;
/**
* List of uneditable fields. Users can't change the value of those fields (like if the user email is `verified`)
*/
const uneditableFields = Object.keys(UserSchema).filter(x => UserSchema[x].isUneditable);
exports.uneditableFields = uneditableFields;
//# sourceMappingURL=UserSchema.js.map