@mikestraczek/cms-auth
Version:
Authentication and user management for the CMS template
154 lines (147 loc) • 4.39 kB
text/typescript
import { PrismaClient } from '@prisma/client';
import { DefaultSession, NextAuthConfig } from 'next-auth';
import { R as Role } from './user-OIjSWV4Y.mjs';
export { C as CreateUserInput, a as Roles, c as UpdateUserInput, U as User, b as UserWithoutPassword } from './user-OIjSWV4Y.mjs';
import { z } from 'zod';
/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*/
declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
role: Role;
email: string;
} & DefaultSession["user"];
}
interface User {
id: string;
role: Role;
email: string;
}
interface JWT {
id: string;
role: Role;
email: string;
}
}
declare function createAuthConfig(db: PrismaClient): NextAuthConfig;
declare const authConfig: typeof createAuthConfig;
declare const ROLE_HIERARCHY: Record<Role, number>;
declare const ROLE_PERMISSIONS: Record<Role, string[]>;
declare function hasRole(userRole: Role, requiredRole: Role): boolean;
declare function hasPermission(userRole: Role, permission: string): boolean;
declare function canAccessAdmin(userRole: Role): boolean;
declare function canManageUsers(userRole: Role): boolean;
type PasswordResetEmailData = {
userEmail: string;
userName: string;
resetPasswordLink: string;
};
declare function sendPasswordResetEmail(data: PasswordResetEmailData): Promise<{
success: boolean;
development: boolean;
error?: undefined;
} | {
success: boolean;
development?: undefined;
error?: undefined;
} | {
success: boolean;
error: unknown;
development?: undefined;
}>;
declare function hashPassword(password: string): Promise<string>;
declare function verifyPassword(password: string, hashedPassword: string): Promise<boolean>;
declare const userSchema: z.ZodObject<{
name: z.ZodString;
email: z.ZodString;
password: z.ZodString;
passwordConfirmation: z.ZodString;
}, "strip", z.ZodTypeAny, {
password: string;
name: string;
email: string;
passwordConfirmation: string;
}, {
password: string;
name: string;
email: string;
passwordConfirmation: string;
}>;
declare const createUserSchema: z.ZodObject<{
name: z.ZodString;
email: z.ZodString;
password: z.ZodString;
passwordConfirmation: z.ZodString;
}, "strip", z.ZodTypeAny, {
password: string;
name: string;
email: string;
passwordConfirmation: string;
}, {
password: string;
name: string;
email: string;
passwordConfirmation: string;
}>;
declare const updateUserSchema: z.ZodObject<{
name: z.ZodString;
email: z.ZodString;
} & {
id: z.ZodString;
password: z.ZodOptional<z.ZodString>;
passwordConfirmation: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
id: string;
name: string;
email: string;
password?: string | undefined;
passwordConfirmation?: string | undefined;
}, {
id: string;
name: string;
email: string;
password?: string | undefined;
passwordConfirmation?: string | undefined;
}>;
declare const loginSchema: z.ZodObject<{
email: z.ZodString;
password: z.ZodString;
}, "strip", z.ZodTypeAny, {
password: string;
email: string;
}, {
password: string;
email: string;
}>;
declare const forgotPasswordSchema: z.ZodObject<{
email: z.ZodString;
}, "strip", z.ZodTypeAny, {
email: string;
}, {
email: string;
}>;
declare const resetPasswordSchema: z.ZodEffects<z.ZodObject<{
password: z.ZodString;
passwordConfirmation: z.ZodString;
token: z.ZodString;
}, "strip", z.ZodTypeAny, {
password: string;
token: string;
passwordConfirmation: string;
}, {
password: string;
token: string;
passwordConfirmation: string;
}>, {
password: string;
token: string;
passwordConfirmation: string;
}, {
password: string;
token: string;
passwordConfirmation: string;
}>;
export { type PasswordResetEmailData, ROLE_HIERARCHY, ROLE_PERMISSIONS, Role, authConfig, canAccessAdmin, canManageUsers, createAuthConfig, createUserSchema, forgotPasswordSchema, hasPermission, hasRole, hashPassword, loginSchema, resetPasswordSchema, sendPasswordResetEmail, updateUserSchema, userSchema, verifyPassword };