Skip to content

Commit

Permalink
Merge pull request #219 from LowerEarthOrbiters/dynamicUsers
Browse files Browse the repository at this point in the history
Dynamically routed users via auth-0
  • Loading branch information
quinnha authored Mar 28, 2024
2 parents 9fb8073 + 3a0deee commit ec0c6e6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/leo-client-app/src/app/api/auth/[auth0]/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getSession } from "@auth0/nextjs-auth0";

export default async function user(req: any, res: any) {
const session = await getSession(req, res);

if (session) {
return res.json({ email: session.user.email });
} else {
return res.json({ email: null });
}
}
17 changes: 11 additions & 6 deletions src/leo-client-app/src/components/SatellitesOfInterest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
DialogTitle,
} from "@mui/material";
import Link from "next/link";
import axios from "axios";
import React, { useEffect, useState } from "react";
import "../styles.css";
import "./styles/satellitesOfInterest.css";
Expand All @@ -35,7 +34,10 @@ type SatelliteDetails = {
};

const SatellitesOfInterest = ({ userId }: Props) => {
const satellites = useGetUserSatellites(userId);
const satellites = useGetUserSatellites(
userId ? userId : "66059b2aa430445956d73120"
);

const queryClient = useQueryClient();

const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -63,13 +65,14 @@ const SatellitesOfInterest = ({ userId }: Props) => {
return (
<div className="satellitesOfInterest">
<Stack alignItems="flex-start" spacing={1}>
<UserName userName="leo" />
<UserName userName={userId} />
<p className="headerBox"></p>
<Stack
className="satellitesOfInterestBox"
alignItems="flex-start"
direction="row"
spacing={5}>
spacing={5}
>
{satellites.data?.satellitesOfInterest?.satellites.length &&
satellites.data?.satellitesOfInterest?.satellites?.map(
(satellite: any, index: number) => (
Expand All @@ -92,7 +95,8 @@ const SatellitesOfInterest = ({ userId }: Props) => {
alignItems: "center",
marginLeft: 2,
marginRight: 2,
}}>
}}
>
<CardContent>
<p className="cardTitle">{satellite.name}</p>
<p className="cardSubtitle">{satellite.noradId}</p>
Expand All @@ -114,7 +118,8 @@ const SatellitesOfInterest = ({ userId }: Props) => {
"var(--material-theme-sys-dark-on-secondary-container)",
},
}}
onClick={handleClickOpen}>
onClick={handleClickOpen}
>
Add Custom Satellite +
</Button>

Expand Down
2 changes: 1 addition & 1 deletion src/leo-client-app/src/components/UserName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const UserName = ({ userName }: Props) => {
color: "var(--material-theme-white)",
}}
>
<span>{userName}&apos;s</span>
<span>{userName}&apos;s</span> <br />
<span> saved satellites</span>
</Box>
);
Expand Down
30 changes: 27 additions & 3 deletions src/leo-client-app/src/pages/satellites-of-interest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,43 @@
import { withPageAuthRequired } from "@auth0/nextjs-auth0/client";
import Navbar from "@/components/navbar/Navbar";
import SatellitesOfInterest from "@/components/SatellitesOfInterest";
import { Grid, Stack } from "@mui/material";
import { Stack } from "@mui/material";
import { useUser } from "@auth0/nextjs-auth0/client";
import axios from "axios";
import { useEffect, useState } from "react";
import { BACKEND_URL } from "@/constants/api";

function SatellitesOfInterestPage() {
const { user, error, isLoading } = useUser();
const [userId, setUserId] = useState("");

const fetchUser = async (email: string) => {
try {
const res = await axios.get(`${BACKEND_URL}/users/getUserByEmail`, {
params: { email: email },
});
setUserId(res.data.user._id);
} catch (error) {
console.error("Error fetching data:", error);
}
};

useEffect(() => {
if (user?.email) {
fetchUser(user.email);
}
}, []);

return (
<main>
<Stack
alignItems="center"
justifyContent="center"
spacing={1}
sx={{ width: "100%", backgroundColor: "var(--material-theme-black)"}}
sx={{ width: "100%", backgroundColor: "var(--material-theme-black)" }}
>
<Navbar />
<SatellitesOfInterest userId="65a5e14ee0d601e0e8c4a387" />
<SatellitesOfInterest userId={userId} />
</Stack>
</main>
);
Expand Down
1 change: 1 addition & 0 deletions src/leo-server-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist/
coverage/
yarn.lock
*.pem
test_*
2 changes: 1 addition & 1 deletion src/leo-server-app/src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dotenv.config({
});

const SocketServer = https.createServer({
cert: fs.readFileSync(process.env.CERT_PATH),
cert: fs.readFileSync(process.env.KEY_CERT),
key: fs.readFileSync(process.env.KEY_PATH),
});

Expand Down

0 comments on commit ec0c6e6

Please sign in to comment.