diff --git a/src/components/ErrorPage.tsx b/src/components/ErrorPage.tsx
index a5da9da..0e6988a 100644
--- a/src/components/ErrorPage.tsx
+++ b/src/components/ErrorPage.tsx
@@ -2,7 +2,7 @@ import { MdError } from "react-icons/md";
import { Button, Text, VStack } from "@chakra-ui/react";
import { useRouter } from "next/router";
-export default function LoadingPage() {
+export default function ErrorPage() {
const router = useRouter();
return (
diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx
index 7e778d5..87af49a 100644
--- a/src/components/Navbar.tsx
+++ b/src/components/Navbar.tsx
@@ -29,10 +29,7 @@ export default function Navbar({variant = 'fixed'}: Props) {
return (
- {status === 'authenticated'
- ? authenticatedLinks
- : <>>
- }
+ {status === 'authenticated' && authenticatedLinks}
);
};
diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts
index fd7aaa6..659825d 100644
--- a/src/pages/api/auth/[...nextauth].ts
+++ b/src/pages/api/auth/[...nextauth].ts
@@ -55,7 +55,5 @@ export default async function auth(req: NextApiRequest, res: NextApiResponse) {
}
async function getUserByEmail(email: string): Promise {
- return prismaClient.user.findUnique({
- where: {email},
- });
+ return prismaClient.user.findUnique({where: {email}});
}
\ No newline at end of file
diff --git a/src/pages/map.tsx b/src/pages/map.tsx
index 4090d99..3a8c695 100644
--- a/src/pages/map.tsx
+++ b/src/pages/map.tsx
@@ -17,11 +17,7 @@ const MapWithNoSSR = dynamic(
);
export default function Map() {
- const [location, setLocation] = useState([
- null as unknown as number,
- null as unknown as number,
- ]);
-
+ const [location, setLocation] = useState([]);
const [geolocationError, setGeolocationError] = useState(false);
const { data: session, status } = useSession();
const [listBars, setListBars] = useState({} as unknown as any);
@@ -116,10 +112,19 @@ export default function Map() {
};
useEffect(() => {
+ if (!session?.user) return;
+
navigator.geolocation.getCurrentPosition(
- successPosition,
- errorPosition,
- geolocationOptions
+ (position: GeolocationPosition) => {
+ setLocation([position.coords.latitude, position.coords.longitude]);
+ setGeolocationError(false);
+ },
+ () => setGeolocationError(true),
+ {
+ enableHighAccuracy: true,
+ timeout: 5000,
+ maximumAge: 0,
+ },
);
}, [loggedUser]);
@@ -134,15 +139,22 @@ export default function Map() {
setLocation([position.coords.latitude, position.coords.longitude]);
setGeolocationError(false);
- if (!loggedUser) return;
- userSetLocation.mutate(
- `${position.coords.latitude},${position.coords.longitude}`
- );
- }
+ for (const [key, val] of Object.entries(params)) {
+ urlBars.searchParams.append(key, val);
+ }
- function errorPosition(error: GeolocationPositionError) {
- setGeolocationError(true);
- }
+ fetch(urlBars)
+ .then(res => res.json())
+ .then(data => {
+ const filteredBars = data.filter((bar: any) => bar.name !== null);
+ setListBars(filteredBars);
+ })
+ .catch(err => console.error(err));
+ }
+ }, [session?.user]);
+
+ if (status === 'loading') return ;
+ const {user} = session as unknown as Session;
return (
<>