Skip to content

Commit c56fde3

Browse files
committed
Fix auth
1 parent 4544cc5 commit c56fde3

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

Diff for: src/components/Navbar/MainNav.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
import { NavBarProps } from "./types";
22
import { NavbarItem } from "./NavbarItem";
3+
import {
4+
SignInButton,
5+
SignOutButton,
6+
SignedIn,
7+
SignedOut,
8+
} from "@clerk/clerk-react";
9+
import { Button } from "../ui/button";
10+
import { usePathname } from "next/navigation";
11+
import { useEffect, useState } from "react";
312

413
export function MainNav({ items }: NavBarProps) {
14+
const pathname = usePathname();
15+
const [redirectUrl, setRedirectUrl] = useState("");
16+
useEffect(() => {
17+
setRedirectUrl(window.location.host);
18+
}, []);
519
return (
620
<nav className={"items-center space-x-4 lg:space-x-6"}>
721
{items.map((item) => (
822
<NavbarItem key={`navbarItem-${item.content}`} item={item} />
923
))}
24+
<SignedOut>
25+
{process.env.NEXT_PUBLIC_SIGN_IN_URL ? (
26+
<Button asChild variant="secondary">
27+
<a
28+
href={`${process.env.NEXT_PUBLIC_SIGN_IN_URL}?redirect_url=https://${redirectUrl}`}
29+
>
30+
Ingresar
31+
</a>
32+
</Button>
33+
) : (
34+
<SignInButton mode="modal" redirectUrl={pathname}>
35+
<Button variant="secondary">Ingresar</Button>
36+
</SignInButton>
37+
)}
38+
</SignedOut>
39+
<SignedIn>
40+
<SignOutButton>
41+
<Button variant={"link"} className="cursor-pointer">
42+
Salir
43+
</Button>
44+
</SignOutButton>
45+
</SignedIn>
1046
</nav>
1147
);
1248
}

Diff for: src/components/Navbar/MobileNav.tsx

+46-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@ import { NavBarProps } from "./types";
99
import { MobileNavbarItem } from "./MobileNavbarItem";
1010
import { MobileLink } from "./MobileLink";
1111
import { Menu, PackageOpen } from "lucide-react";
12+
import {
13+
SignInButton,
14+
SignOutButton,
15+
SignedIn,
16+
SignedOut,
17+
} from "@clerk/clerk-react";
18+
import { usePathname } from "next/navigation";
19+
import { useEffect, useState } from "react";
1220

1321
export function MobileNav({ items }: NavBarProps) {
14-
const [open, setOpen] = React.useState(false);
22+
const [open, setOpen] = useState(false);
23+
const pathname = usePathname();
24+
const [redirectUrl, setRedirectUrl] = useState("");
25+
useEffect(() => {
26+
setRedirectUrl(window.location.host);
27+
}, []);
1528

1629
return (
1730
<Sheet open={open} onOpenChange={setOpen}>
@@ -32,7 +45,7 @@ export function MobileNav({ items }: NavBarProps) {
3245
>
3346
<PackageOpen className="h-5 w-5" />
3447
</MobileLink>
35-
<ScrollArea className="my-4 h-[calc(100vh-8rem)] pb-10 pl-6">
48+
<ScrollArea className="my-4 h-[calc(100vh-8rem)] px-6 pb-10">
3649
<div className="flex flex-col space-y-2">
3750
<div className="flex flex-col space-y-3 pt-6">
3851
{items.map((item) => (
@@ -42,6 +55,37 @@ export function MobileNav({ items }: NavBarProps) {
4255
setOpen={setOpen}
4356
/>
4457
))}
58+
<SignedOut>
59+
{process.env.NEXT_PUBLIC_SIGN_IN_URL ? (
60+
<Button asChild variant="link">
61+
<a
62+
href={`${process.env.NEXT_PUBLIC_SIGN_IN_URL}?redirect_url=https://${redirectUrl}`}
63+
>
64+
Ingresar
65+
</a>
66+
</Button>
67+
) : (
68+
<SignInButton mode="modal" redirectUrl={pathname}>
69+
<Button variant="link" onClick={() => setOpen(false)}>
70+
Ingresar
71+
</Button>
72+
</SignInButton>
73+
)}
74+
</SignedOut>
75+
<SignedIn>
76+
<SignOutButton>
77+
<div
78+
className="cursor-pointer text-muted-foreground"
79+
onClick={() => {
80+
setOpen(false);
81+
}}
82+
// item={{ link: "#", content: "Salir" }}
83+
// setOpen={setOpen}
84+
>
85+
Salir
86+
</div>
87+
</SignOutButton>
88+
</SignedIn>
4589
</div>
4690
</div>
4791
</ScrollArea>

Diff for: src/components/nav.tsx

-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ export const Nav = () => {
2525
content: "Comunidades",
2626
link: "/",
2727
},
28-
{
29-
content: "Login",
30-
link: "/sign-in",
31-
},
32-
{
33-
content: "Regístrate",
34-
link: "/sign-up",
35-
},
3628
] satisfies NavbarMenuItem[],
3729
[],
3830
);

0 commit comments

Comments
 (0)