bruh
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
// Import required modules
|
// Import required modules
|
||||||
import mongoose from "mongoose";
|
import mongoose from "mongoose";
|
||||||
import UserModel from "../models/UserModel";
|
import { UserModel } from "../models/UserModel";
|
||||||
import * as dotenv from "dotenv";
|
import * as dotenv from "dotenv";
|
||||||
import { api } from '../utils/api'
|
import { api } from '../utils/api'
|
||||||
|
|
||||||
|
@ -33,7 +33,4 @@ const userSchema = new Schema<InterfaceUsers>({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const UserModel = model<InterfaceUsers>('users', userSchema);
|
export const UserModel = model<InterfaceUsers>('users', userSchema);
|
||||||
|
|
||||||
|
|
||||||
export default UserModel;
|
|
||||||
|
@ -11,6 +11,15 @@ const Login: React.FC = () => {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const login = async (event: React.FormEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
try {
|
||||||
|
|
||||||
|
} catch(error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const returnHome = () => {
|
const returnHome = () => {
|
||||||
router.push("/");
|
router.push("/");
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,7 @@ const Signup: React.FC = () => {
|
|||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(response);
|
console.log(response);
|
||||||
alert("Registration Complete! Now login.");
|
alert("Registration Complete! Now login.");
|
||||||
router.push("/Login");
|
router.push("/Login");
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
} from "~/server/api/trpc";
|
} from "~/server/api/trpc";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
|
||||||
import UserModel from "~/models/UserModel";
|
import { UserModel } from "~/models/UserModel";
|
||||||
|
|
||||||
// Main login router for backend
|
// Main login router for backend
|
||||||
export const loginRouter = createTRPCRouter({
|
export const loginRouter = createTRPCRouter({
|
||||||
@ -30,6 +30,7 @@ export const loginRouter = createTRPCRouter({
|
|||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Account with email already exists!",
|
message: "Account with email already exists!",
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
const saltRounds = 10;
|
const saltRounds = 10;
|
||||||
const hashedPassword: string = await bcrypt.hash(input.password, saltRounds);
|
const hashedPassword: string = await bcrypt.hash(input.password, saltRounds);
|
||||||
|
@ -12,7 +12,7 @@ import { type Session } from "next-auth";
|
|||||||
import superjson from "superjson";
|
import superjson from "superjson";
|
||||||
import { ZodError } from "zod";
|
import { ZodError } from "zod";
|
||||||
import { dbconnect } from "~/clients/mongoose";
|
import { dbconnect } from "~/clients/mongoose";
|
||||||
import UserModel from "~/models/UserModel";
|
import { UserModel } from "~/models/UserModel";
|
||||||
|
|
||||||
import { getServerAuthSession } from "~/server/auth";
|
import { getServerAuthSession } from "~/server/auth";
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ interface CreateContextOptions {
|
|||||||
*/
|
*/
|
||||||
const createInnerTRPCContext = async (opts: CreateContextOptions) => {
|
const createInnerTRPCContext = async (opts: CreateContextOptions) => {
|
||||||
// Connect our database in inner context
|
// Connect our database in inner context
|
||||||
|
await dbconnect();
|
||||||
return {
|
return {
|
||||||
session: opts.session,
|
session: opts.session,
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ export const createTRPCContext = async ({
|
|||||||
}: CreateNextContextOptions) => {
|
}: CreateNextContextOptions) => {
|
||||||
// Get the session from the server using the getServerSession wrapper function
|
// Get the session from the server using the getServerSession wrapper function
|
||||||
const session = await getServerAuthSession({ req, res });
|
const session = await getServerAuthSession({ req, res });
|
||||||
await dbconnect();
|
|
||||||
return createInnerTRPCContext({
|
return createInnerTRPCContext({
|
||||||
session,
|
session,
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user