mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-21 21:06:20 +02:00
25 lines
682 B
TypeScript
25 lines
682 B
TypeScript
import Link, { LinkProps } from "next/link";
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
import React from "react";
|
|
|
|
export const LoginLink = React.forwardRef<
|
|
HTMLAnchorElement,
|
|
React.PropsWithChildren<Omit<LinkProps, "href"> & { className?: string }>
|
|
>(function LoginLink({ children, ...props }, ref) {
|
|
const router = useRouter();
|
|
const pathname = usePathname() ?? "/";
|
|
return (
|
|
<Link
|
|
ref={ref}
|
|
{...props}
|
|
href="/login"
|
|
onClick={async (e) => {
|
|
e.preventDefault();
|
|
props.onClick?.(e);
|
|
router.push("/login?callbackUrl=" + encodeURIComponent(pathname));
|
|
}}
|
|
>
|
|
{children}
|
|
</Link>
|
|
);
|
|
});
|