Home / File/ user.server.ts — ui Source File

user.server.ts — ui Source File

Architecture documentation for user.server.ts, a typescript file in the ui codebase. 3 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  e9751ef9_7e9e_b5e0_4d72_0eda9c53a321["user.server.ts"]
  0e9e6e0c_89c3_710e_bf21_50ad9d751025["client"]
  e9751ef9_7e9e_b5e0_4d72_0eda9c53a321 --> 0e9e6e0c_89c3_710e_bf21_50ad9d751025
  8c2ad8d1_012f_3c36_7837_7267d34cd794["bcryptjs"]
  e9751ef9_7e9e_b5e0_4d72_0eda9c53a321 --> 8c2ad8d1_012f_3c36_7837_7267d34cd794
  7b14a427_4501_6a47_9ad1_843ac38610ff["db.server"]
  e9751ef9_7e9e_b5e0_4d72_0eda9c53a321 --> 7b14a427_4501_6a47_9ad1_843ac38610ff
  style e9751ef9_7e9e_b5e0_4d72_0eda9c53a321 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { Password, User } from "@prisma/client";
import bcrypt from "bcryptjs";

import { prisma } from "~/db.server";

export type { User } from "@prisma/client";

export async function getUserById(id: User["id"]) {
  return prisma.user.findUnique({ where: { id } });
}

export async function getUserByEmail(email: User["email"]) {
  return prisma.user.findUnique({ where: { email } });
}

export async function createUser(email: User["email"], password: string) {
  const hashedPassword = await bcrypt.hash(password, 10);

  return prisma.user.create({
    data: {
      email,
      password: {
        create: {
          hash: hashedPassword,
        },
      },
    },
  });
}

export async function deleteUserByEmail(email: User["email"]) {
  return prisma.user.delete({ where: { email } });
}

export async function verifyLogin(
  email: User["email"],
  password: Password["hash"],
) {
  const userWithPassword = await prisma.user.findUnique({
    where: { email },
    include: {
      password: true,
    },
  });

  if (!userWithPassword || !userWithPassword.password) {
    return null;
  }

  const isValid = await bcrypt.compare(
    password,
    userWithPassword.password.hash,
  );

  if (!isValid) {
    return null;
  }

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  const { password: _password, ...userWithoutPassword } = userWithPassword;

  return userWithoutPassword;
}

Subdomains

Dependencies

  • bcryptjs
  • client
  • db.server

Frequently Asked Questions

What does user.server.ts do?
user.server.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain, TemplateSync subdomain.
What functions are defined in user.server.ts?
user.server.ts defines 5 function(s): createUser, deleteUserByEmail, getUserByEmail, getUserById, verifyLogin.
What does user.server.ts depend on?
user.server.ts imports 3 module(s): bcryptjs, client, db.server.
Where is user.server.ts in the architecture?
user.server.ts is located at packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models/user.server.ts (domain: FrameworkTooling, subdomain: TemplateSync, directory: packages/shadcn/test/fixtures/frameworks/remix-indie-stack/app/models).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free