Openstatus
www.openstatus.dev
1"use client";
2
3import { createProtectedCookieKey } from "@/lib/protected";
4import { useParams } from "next/navigation";
5import { parseAsString, useQueryState } from "nuqs";
6import { useEffect } from "react";
7
8export function PasswordWrapper({ children }: { children?: React.ReactNode }) {
9 const [password, setPassword] = useQueryState("pw", parseAsString);
10 const { domain } = useParams<{ domain: string }>();
11
12 useEffect(() => {
13 if (password) {
14 const key = createProtectedCookieKey(domain);
15 document.cookie = `${key}=${password}; path=/; expires=${new Date(
16 Date.now() + 1000 * 60 * 60 * 24 * 30,
17 ).toUTCString()}`;
18 setPassword(null);
19 }
20 }, [password, domain, setPassword]);
21
22 return children;
23}