auth service

This commit is contained in:
Alex Holliday committed 2026-01-07 19:50:06 +00:00
1 parent a3e24b5420
commit 9248870716
29 files changed
+394 -288

No files matched your search

+13 -1
View File
@@ -3,6 +3,18 @@ import mongoose, { Schema, Document, Types } from "mongoose";
export const ScopeTypes = ["organization", "team"] as const;
export type ScopeType = (typeof ScopeTypes)[number];
type IdLike = string | Types.ObjectId;
export type RoleLike = {
_id: IdLike;
organizationId: IdLike;
name: string;
scope: ScopeType;
permissions: string[];
createdAt: Date;
updatedAt: Date;
};
export interface IRole extends Document {
_id: Types.ObjectId;
organizationId: Types.ObjectId;
@@ -15,7 +27,7 @@ export interface IRole extends Document {
const roleSchema = new Schema<IRole>(
{
organizationId: { type: Schema.Types.ObjectId, ref: "Org" },
organizationId: { type: Schema.Types.ObjectId, ref: "Org", required: true },
name: { type: String, required: true },
scope: { type: String, enum: ScopeTypes, required: true },
permissions: { type: [String], default: [] },
-37
View File
@@ -2,43 +2,6 @@ import mongoose, { Schema, Document, Types } from "mongoose";
import { IRole, ITeam } from "@/db/models/index.js";
import { Entitlements } from "@/types/entitlements.js";
export interface ITokenizedUser {
sub: string;
email: string;
orgId: string;
}
export interface IUserContext {
sub: string;
email: string;
orgId: string;
teamIds?: string[];
teams?: ITeam[];
currentTeamId?: string;
roles?: {
orgRole?: IRole;
teamRole: IRole;
};
entitlements: Entitlements;
}
export interface IUserReturnable {
id: string;
email: string;
firstName: string;
lastName: string;
org: {
name: string;
planKey: string;
permissions: string[];
};
teams: {
id: string;
name: string;
permissions: string[];
}[];
entitlements: Entitlements;
}
export interface IUser extends Document {
_id: Types.ObjectId;
firstName: string;
+2 -8
View File
@@ -7,13 +7,7 @@ export { MonitorStats } from "./monitors/MonitorStats.js";
export type { IMonitorStats } from "./monitors/MonitorStats.js";
export { User } from "./auth/User.js";
export type {
IUser,
ITokenizedUser,
IUserReturnable,
IUserContext,
IUserProfile,
} from "./auth/User.js";
export type { IUser, IUserProfile } from "./auth/User.js";
export {
NotificationChannel,
@@ -25,7 +19,7 @@ export { Invite } from "./auth/Invite.js";
export type { IInvite } from "./auth/Invite.js";
export { Role } from "./auth/Role.js";
export type { IRole } from "./auth/Role.js";
export type { IRole, RoleLike } from "./auth/Role.js";
export { Maintenance } from "./maintenance/Maintenance.js";
export type { IMaintenance } from "./maintenance/Maintenance.js";