Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

780 B
Raw Blame
import mongoose, { Schema, Document, Types } from 'mongoose';

export interface IKey extends Document {
  userId: Types.ObjectId;
  name: string;
  value: string;
  expiresAt?: Date;
  tenantId?: string;
}

const keySchema: Schema<IKey> = new Schema({
  userId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true,
  },
  name: {
    type: String,
    required: true,
  },
  value: {
    type: String,
    required: true,
  },
  expiresAt: {
    type: Date,
  },
  tenantId: {
    type: String,
    index: true,
  },
});

keySchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
/** Not unique: legacy databases can hold duplicate rows for one user and key name. */
keySchema.index({ userId: 1, name: 1, tenantId: 1 });

export default keySchema;