This commit is contained in:
2023-10-27 16:38:06 -04:00
parent 730b9939dd
commit f56ce1c7d8
6 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,6 @@
// Import required modules
import mongoose from "mongoose";
import UserModel from "../models/UserModel";
import { UserModel } from "../models/UserModel";
import * as dotenv from "dotenv";
import { api } from '../utils/api'

View File

@ -33,7 +33,4 @@ const userSchema = new Schema<InterfaceUsers>({
],
});
const UserModel = model<InterfaceUsers>('users', userSchema);
export default UserModel;
export const UserModel = model<InterfaceUsers>('users', userSchema);

View File

@ -11,6 +11,15 @@ const Login: React.FC = () => {
const router = useRouter();
const login = async (event: React.FormEvent) => {
event.preventDefault();
try {
} catch(error) {
}
}
const returnHome = () => {
router.push("/");
};

View File

@ -27,6 +27,7 @@ const Signup: React.FC = () => {
username: username,
password: password,
})
console.log(response);
alert("Registration Complete! Now login.");
router.push("/Login");

View File

@ -8,7 +8,7 @@ import {
} from "~/server/api/trpc";
import { TRPCError } from "@trpc/server";
import UserModel from "~/models/UserModel";
import { UserModel } from "~/models/UserModel";
// Main login router for backend
export const loginRouter = createTRPCRouter({
@ -30,6 +30,7 @@ export const loginRouter = createTRPCRouter({
code: "BAD_REQUEST",
message: "Account with email already exists!",
})
}
const saltRounds = 10;
const hashedPassword: string = await bcrypt.hash(input.password, saltRounds);

View File

@ -12,7 +12,7 @@ import { type Session } from "next-auth";
import superjson from "superjson";
import { ZodError } from "zod";
import { dbconnect } from "~/clients/mongoose";
import UserModel from "~/models/UserModel";
import { UserModel } from "~/models/UserModel";
import { getServerAuthSession } from "~/server/auth";
@ -40,6 +40,7 @@ interface CreateContextOptions {
*/
const createInnerTRPCContext = async (opts: CreateContextOptions) => {
// Connect our database in inner context
await dbconnect();
return {
session: opts.session,
@ -58,7 +59,7 @@ export const createTRPCContext = async ({
}: CreateNextContextOptions) => {
// Get the session from the server using the getServerSession wrapper function
const session = await getServerAuthSession({ req, res });
await dbconnect();
return createInnerTRPCContext({
session,
});