Skip to content

Commit

Permalink
Fix duplicate router
Browse files Browse the repository at this point in the history
  • Loading branch information
theNatePi committed Jan 14, 2025
2 parents 1154de2 + 518a943 commit c656e3c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 36 deletions.
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div id="root"></div>
<script
type="module"
src="/src/main.tsx"
src="/src/main.jsx"
></script>
</body>
</html>
1 change: 0 additions & 1 deletion client/src/App.tsx → client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { Admin } from "./components/admin/Admin";
import { CatchAll } from "./components/CatchAll";
import { Dashboard } from "./components/dashboard/Dashboard";
//@ts-expect-error - Allow import of JSX page into App.tsx base
import { Playground } from "./components/playground/Playground";
import { Login } from "./components/login/Login";
import { ProtectedRoute } from "./components/ProtectedRoute";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const signinSchema = z.object({
password: z.string().min(6, "Password must be at least 6 characters long"),
});

type SigninFormValues = z.infer<typeof signinSchema>;

export const Login = () => {
const navigate = useNavigate();
const toast = useToast();
Expand All @@ -42,13 +40,13 @@ export const Login = () => {
register,
handleSubmit,
formState: { errors },
} = useForm<SigninFormValues>({
} = useForm({
resolver: zodResolver(signinSchema),
mode: "onBlur",
});

const toastLoginError = useCallback(
(msg: string) => {
(msg) => {
toast({
title: "An error occurred while signing in",
description: msg,
Expand All @@ -59,7 +57,7 @@ export const Login = () => {
[toast]
);

const handleLogin = async (data: SigninFormValues) => {
const handleLogin = async (data) => {
try {
await login({
email: data.email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const signupSchema = z.object({
password: z.string().min(6, "Password must be at least 6 characters long"),
});

type SignupFormValues = z.infer<typeof signupSchema>;

export const Signup = () => {
const navigate = useNavigate();
const toast = useToast();
Expand All @@ -41,16 +39,19 @@ export const Signup = () => {
register,
handleSubmit,
formState: { errors },
} = useForm<SignupFormValues>({
} = useForm({
resolver: zodResolver(signupSchema),
mode: "onBlur",
});

const handleSignup = async (data: SignupFormValues) => {
const handleSignup = async (data) => {
try {
const user = await signup({
email: data.email,
password: data.password,
// add:
// first_name: ...
// last_name: ...
});

if (user) {
Expand Down
6 changes: 5 additions & 1 deletion client/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const AuthContext = createContext<AuthContextProps | null>(null);
interface EmailPassword {
email: string;
password: string;
first_name: string;
last_name: string;
}

export const AuthProvider = ({ children }: { children: ReactNode }) => {
Expand All @@ -43,7 +45,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
const [currentUser, setCurrentUser] = useState<User | null>(null);
const [loading, setLoading] = useState(true);

const signup = async ({ email, password }: EmailPassword) => {
const signup = async ({ email, password, first_name, last_name }: EmailPassword) => {
if (currentUser) {
signOut(auth);
}
Expand All @@ -57,6 +59,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
await backend.post("/users/create", {
email: email,
firebaseUid: userCredential.user.uid,
first_name: first_name,
last_name: last_name
});

return userCredential;
Expand Down
32 changes: 32 additions & 0 deletions client/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";

import { ChakraProvider, extendTheme } from "@chakra-ui/react";

import App from "./App.jsx";

const colors = {
brand: {},
};

const theme = extendTheme({ colors });

// For TSX
// createRoot(document.getElementById("root")!).render(
// <StrictMode>
// <ChakraProvider theme={theme}>
// <App />
// </ChakraProvider>
// </StrictMode>
// );

const root = document.getElementById('root');
if (root) {
createRoot(root).render(
<StrictMode>
<ChakraProvider theme={theme}>
<App />
</ChakraProvider>
</StrictMode>
);
}
20 changes: 0 additions & 20 deletions client/src/main.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ usersRouter.delete("/id/:id", async (req, res) => {
// Create user
usersRouter.post("/create", async (req, res) => {
try {
const { email, firebaseUid } = req.body;
const { email, firebaseUid, first_name, last_name } = req.body;

const user = await db.query(
"INSERT INTO users (email, firebase_uid) VALUES ($1, $2) RETURNING *",
[email, firebaseUid]
"INSERT INTO users (email, firebase_uid, first_name, last_name, edit_perms) VALUES ($1, $2, $3, $4, $5) RETURNING *",
[email, firebaseUid, first_name, last_name, false]
);

res.status(200).json(keysToCamel(user));
Expand Down
1 change: 0 additions & 1 deletion server/src/app.ts → server/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { commentsRouter } from '../routes/comments';
import { eventsRouter } from "../routes/events";
import { bookingsRouter } from "../routes/bookings";
import { verifyToken } from "./middleware";
import { commentsRouter } from "../routes/comments";
import { clientsRouter } from "../routes/clients";

dotenv.config();
Expand Down

0 comments on commit c656e3c

Please sign in to comment.