Skip to content

Instantly share code, notes, and snippets.

@onimenotsuki
Created March 17, 2020 05:01
Show Gist options
  • Save onimenotsuki/13fd3d6b253759c01e4b9840ccbdab5e to your computer and use it in GitHub Desktop.
Save onimenotsuki/13fd3d6b253759c01e4b9840ccbdab5e to your computer and use it in GitHub Desktop.
Tutorial: Parte 1: Autenticación por medio de API con JWT, ExpressJS, ReactJS y React Native -> User Model
const mongoose = require('mongoose');
const validator = require('validator');
const Schema = mongoose.Schema;
const UserSchema = new Schema(
{
username: {
type: String,
required: true,
unique: true,
validate: (value) => {
const regexp = /^(?=.{8,20}$)(?![_.])(?!.*[_.]{2})[a-zA-Z0-9._]+(?<![_.])$/;
return regexp.test(value);
},
},
email: {
type: String,
required: true,
unique: true,
lowercase: true,
validate: (value) => validator.isEmail(value),
},
password: {
type: String,
required: true,
},
},
{ timestamps: true },
);
module.exports = mongoose.model('User', UserSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment