Revert "Merge pull request #2973 from bluewave-labs/feat/v2/auth"

This reverts commit 72882fded9, reversing
changes made to bfb299cfca.
This commit is contained in:
Alex Holliday committed 2025-09-23 14:05:23 -07:00
1 parent 003d419a64
commit 990aed9f2e
25 files changed
+69 -894

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import mongoose from "mongoose";
const InviteTokenSchema = mongoose.Schema(
{
email: {
type: String,
required: true,
unique: true,
},
teamId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Team",
immutable: true,
required: true,
},
role: {
type: Array,
required: true,
default: ["user"],
},
token: {
type: String,
required: true,
},
expiry: {
type: Date,
default: Date.now,
expires: 3600,
},
},
{
timestamps: true,
}
);
export default mongoose.model("InviteToken", InviteTokenSchema);
@@ -1,47 +1,11 @@
import mongoose, { Schema, Document, Types } from "mongoose";
import mongoose from "mongoose";
import bcrypt from "bcryptjs";
import logger from "../../../utils/logger.js";
import Monitor from "../Monitor.js";
import Team from "../Team.js";
import Notification from "../Notification.js";
import { subscribe } from "diagnostics_channel";
import logger from "../../utils/logger.js";
import Monitor from "./Monitor.js";
import Team from "./Team.js";
import Notification from "./Notification.js";
export const RoleTypes = ["user", "admin", "superadmin", "demo"] as const;
export type RoleType = (typeof RoleTypes)[number];
export interface ITokenizedUser {
sub: string;
roles: string[];
}
export interface IUser extends Document {
// V1
_id: Types.ObjectId;
firstName: string;
lastName: string;
email: string;
password: string;
avatarImage: string;
profileImage: {
data: Buffer;
contentType: string;
};
isActive: boolean;
isVerified: boolean;
role?: RoleType[];
teamId: Types.ObjectId;
checkTTL: number;
createdAt: Date;
updatedAt: Date;
comparePassword: (submittedPassword: string) => Promise<boolean>;
// V2
roles: Types.ObjectId[];
lastLoginAt?: Date;
version: number;
}
const UserSchema = new Schema<IUser>(
const UserSchema = mongoose.Schema(
{
firstName: {
type: String,
@@ -58,7 +22,7 @@ const UserSchema = new Schema<IUser>(
},
password: {
type: String,
required: false,
required: true,
},
avatarImage: {
type: String,
@@ -77,8 +41,8 @@ const UserSchema = new Schema<IUser>(
},
role: {
type: [String],
default: ["user"],
enum: RoleTypes,
default: "user",
enum: ["user", "admin", "superadmin", "demo"],
},
teamId: {
type: mongoose.Schema.Types.ObjectId,
@@ -88,22 +52,6 @@ const UserSchema = new Schema<IUser>(
checkTTL: {
type: Number,
},
// v2
roles: [
{
type: Schema.Types.ObjectId,
ref: "Role",
default: [],
},
],
lastLoginAt: {
type: Date,
},
version: {
type: Number,
default: 1,
},
},
{
timestamps: true,
@@ -121,7 +69,7 @@ UserSchema.pre("save", function (next) {
UserSchema.pre("findOneAndUpdate", function (next) {
const update = this.getUpdate();
if (update && "password" in update) {
if ("password" in update) {
const salt = bcrypt.genSaltSync(10);
update.password = bcrypt.hashSync(update.password, salt);
}
@@ -144,13 +92,15 @@ UserSchema.pre("findOneAndDelete", async function (next) {
}
next();
} catch (error) {
next(error as Error);
next(error);
}
});
UserSchema.methods.comparePassword = async function (submittedPassword: string) {
UserSchema.methods.comparePassword = async function (submittedPassword) {
const res = await bcrypt.compare(submittedPassword, this.password);
return res;
};
export const User = mongoose.model<IUser>("User", UserSchema);
const User = mongoose.model("User", UserSchema);
export default User;
-68
View File
@@ -1,68 +0,0 @@
import mongoose, { Schema, Document, Types } from "mongoose";
export interface IInvite extends Document {
// v1
_id: Types.ObjectId;
email: string;
teamId: Types.ObjectId;
role: string[];
token: string;
expiry: Date;
createdAt: Date;
updatedAt: Date;
// v2
tokenHash: string;
roles: Types.ObjectId[];
createdBy: Types.ObjectId;
updatedBy: Types.ObjectId;
}
const InviteSchema = new Schema<IInvite>(
{
email: {
type: String,
required: true,
unique: true,
trim: true,
lowercase: true,
},
teamId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Team",
immutable: true,
required: true,
},
role: {
type: [String],
required: true,
default: ["user"],
},
token: {
type: String,
required: true,
},
expiry: {
type: Date,
default: Date.now,
expires: 3600,
},
// v2
roles: [
{
type: Schema.Types.ObjectId,
ref: "Role",
required: true,
},
],
tokenHash: { type: String, required: true, unique: true },
createdBy: { type: Schema.Types.ObjectId, ref: "User", required: true },
updatedBy: { type: Schema.Types.ObjectId, ref: "User", required: true },
},
{
timestamps: true,
}
);
export const Invite = mongoose.model<IInvite>("Invite", InviteSchema);
-45
View File
@@ -1,45 +0,0 @@
import mongoose, { Schema, Document, Types } from "mongoose";
export interface IRole extends Document {
_id: Types.ObjectId;
name: string;
description?: string;
permissions: string[];
isActive: boolean;
createdAt: Date;
updatedAt: Date;
}
const roleSchema = new Schema<IRole>(
{
name: {
type: String,
required: true,
trim: true,
maxlength: 50,
},
description: {
type: String,
trim: true,
maxlength: 200,
},
permissions: [
{
type: String,
required: true,
},
],
isActive: {
type: Boolean,
default: true,
},
},
{
timestamps: true,
}
);
roleSchema.index({ name: 1 }, { unique: true });
export const Role = mongoose.model<IRole>("Role", roleSchema);
-9
View File
@@ -1,9 +0,0 @@
export { User } from "./auth/User.js";
export type { IUser } from "./auth/User.js";
export type { ITokenizedUser } from "./auth/User.js";
export { Role } from "./auth/Role.js";
export type { IRole } from "./auth/Role.js";
export type { IInvite } from "./auth/Invite.js";
export { Invite } from "./auth/Invite.js";
export { Migration } from "./migration/Migration.js";
export type { IMigration } from "./migration/Migration.js";
@@ -1,34 +0,0 @@
import mongoose, { Schema, Document, Types } from "mongoose";
export interface IMigration extends Document {
_id: Types.ObjectId;
name: string;
runAt: Date;
success: boolean;
createdAt: Date;
updatedAt: Date;
}
const migrationSchema = new Schema<IMigration>(
{
name: {
type: String,
required: true,
},
runAt: {
type: Date,
required: false,
},
success: {
type: Boolean,
required: false,
},
},
{
timestamps: true,
}
);
migrationSchema.index({ name: 1 }, { unique: true });
export const Migration = mongoose.model<IMigration>("Migration", migrationSchema);