mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-14 05:24:24 +01:00
* refactor: `packages/api` build scripts for better inline debugging * refactor: Explicitly select secure fields as no longer returned by default, exclude backupCodes from user data retrieval in authentication and 2FA processes * refactor: Backup Codes UI to not expect backup codes, only regeneration * refactor: Ensure secure fields are deleted from user data in getUserController
153 lines
2.7 KiB
TypeScript
153 lines
2.7 KiB
TypeScript
import { Schema } from 'mongoose';
|
|
import { SystemRoles } from 'librechat-data-provider';
|
|
import { IUser } from '~/types';
|
|
|
|
// Session sub-schema
|
|
const SessionSchema = new Schema(
|
|
{
|
|
refreshToken: {
|
|
type: String,
|
|
default: '',
|
|
},
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
// Backup code sub-schema
|
|
const BackupCodeSchema = new Schema(
|
|
{
|
|
codeHash: { type: String, required: true },
|
|
used: { type: Boolean, default: false },
|
|
usedAt: { type: Date, default: null },
|
|
},
|
|
{ _id: false },
|
|
);
|
|
|
|
const userSchema = new Schema<IUser>(
|
|
{
|
|
name: {
|
|
type: String,
|
|
},
|
|
username: {
|
|
type: String,
|
|
lowercase: true,
|
|
default: '',
|
|
},
|
|
email: {
|
|
type: String,
|
|
required: [true, "can't be blank"],
|
|
lowercase: true,
|
|
unique: true,
|
|
match: [/\S+@\S+\.\S+/, 'is invalid'],
|
|
index: true,
|
|
},
|
|
emailVerified: {
|
|
type: Boolean,
|
|
required: true,
|
|
default: false,
|
|
},
|
|
password: {
|
|
type: String,
|
|
trim: true,
|
|
minlength: 8,
|
|
maxlength: 128,
|
|
select: false,
|
|
},
|
|
avatar: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
provider: {
|
|
type: String,
|
|
required: true,
|
|
default: 'local',
|
|
},
|
|
role: {
|
|
type: String,
|
|
default: SystemRoles.USER,
|
|
},
|
|
googleId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
facebookId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
openidId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
samlId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
ldapId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
githubId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
discordId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
appleId: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true,
|
|
},
|
|
plugins: {
|
|
type: Array,
|
|
},
|
|
twoFactorEnabled: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
totpSecret: {
|
|
type: String,
|
|
select: false,
|
|
},
|
|
backupCodes: {
|
|
type: [BackupCodeSchema],
|
|
select: false,
|
|
},
|
|
refreshToken: {
|
|
type: [SessionSchema],
|
|
},
|
|
expiresAt: {
|
|
type: Date,
|
|
expires: 604800, // 7 days in seconds
|
|
},
|
|
termsAccepted: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
personalization: {
|
|
type: {
|
|
memories: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
},
|
|
default: {},
|
|
},
|
|
/** Field for external source identification (for consistency with TPrincipal schema) */
|
|
idOnTheSource: {
|
|
type: String,
|
|
sparse: true,
|
|
},
|
|
},
|
|
{ timestamps: true },
|
|
);
|
|
|
|
export default userSchema;
|