Spaces:
Sleeping
Sleeping
final stuffs
Browse filesFiles changed (3)
1234567872 unmodified lines81828384858687888990919293import { NextRequest, NextResponse } from "next/server";// import { cookies } from "next/headers";// import MY_TOKEN_KEY from "@/lib/get-cookie-name";// TODO refacto to do not use the window.postMessage, doesn't work with iFrameexport async function GET() {const redirect_uri = process.env.REDIRECT_URI;72 unmodified lines);}const user = await userResponse.json();// const cookieStore = await cookies();// cookieStore.set(MY_TOKEN_KEY(), response.access_token, {// maxAge: response.expires_in,// httpOnly: false,// secure: true,// sameSite: "lax",// });return NextResponse.json({123472 unmodified lines777879808182import { NextRequest, NextResponse } from "next/server";export async function GET() {const redirect_uri = process.env.REDIRECT_URI;72 unmodified lines);}const user = await userResponse.json();return NextResponse.json({
12345678910111213141516171819202122232425262728"use client";import { use } from "react";import { useBroadcastChannel } from "@/lib/useBroadcastChannel";import { useMount } from "react-use";export default function AuthCallback({searchParams,}: {searchParams: Promise<{ code: string }>;}) {const { code } = use(searchParams);const { postMessage } = useBroadcastChannel("auth", () => {});useMount(() => {console.log("AuthCallback mounted", code);if (code) {postMessage({code: code,type: "user-oauth",});// window.close();return;}});return <div>Login in progress ...</div>;}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960"use client";import { useUser } from "@/hooks/useUser";import { use } from "react";import { useMount } from "react-use";import { Button } from "@/components/ui/button";import Link from "next/link";export default function AuthCallback({searchParams,}: {searchParams: Promise<{ code: string }>;}) {const { code } = use(searchParams);const { loginFromCode } = useUser();useMount(async () => {if (code) {await loginFromCode(code);}});return (<div className="h-screen flex flex-col justify-center items-center"><div className="!rounded-2xl !p-0 !bg-white !border-neutral-100 min-w-xs text-center overflow-hidden ring-[8px] ring-white/20"><header className="bg-neutral-50 p-6 border-b border-neutral-200/60"><div className="flex items-center justify-center -space-x-4 mb-3"><div className="size-9 rounded-full bg-pink-200 shadow-2xs flex items-center justify-center text-xl opacity-50">🚀</div><div className="size-11 rounded-full bg-amber-200 shadow-2xl flex items-center justify-center text-2xl z-2">👋</div><div className="size-9 rounded-full bg-sky-200 shadow-2xs flex items-center justify-center text-xl opacity-50">🙌</div></div><p className="text-xl font-semibold text-neutral-950">Login In Progress...</p><p className="text-sm text-neutral-500 mt-1.5">Wait a moment while we log you in with your code.</p></header><main className="space-y-4 p-6"><div><p className="text-sm text-neutral-700 mb-4 max-w-xs">If you are not redirected automatically, please click the buttonbelow:</p><Link href="/"><Button variant="black" className="relative">Go to Home</Button></Link></div></main></div></div>);}
16 unmodified lines17181920212223 unmodified lines46474849505152535455563 unmodified lines606162636465665 unmodified lines72737475767716 unmodified linesconst client = useQueryClient();const router = useRouter();const [, setCookie, removeCookie] = useCookie(cookie_name);const { data: { user, errCode } = { user: null, errCode: null }, isLoading } =useQuery({23 unmodified lines};const openLoginWindow = async () => {return window.open("/auth","Login to DeepSite","menubar=no,width=500,height=777,location=no,resizable=no,scrollbars=yes,status=no");};const loginFromCode = async (code: string) => {3 unmodified lines.post("/auth", { code }).then(async (res: any) => {if (res.data) {// fix to be able to set the cookie through the space (Hugging Face)setCookie(res.data.access_token, {expires: res.data.expires_in? new Date(Date.now() + res.data.expires_in * 1000)5 unmodified linesuser: res.data.user,errCode: null,});toast.success("Login successful");}})16 unmodified lines1718192021222323 unmodified lines47484950515253543 unmodified lines5859606162635 unmodified lines69707172737475767778798016 unmodified linesconst client = useQueryClient();const router = useRouter();const [, setCookie, removeCookie] = useCookie(cookie_name);const [currentRoute, setCurrentRoute] = useCookie("deepsite-currentRoute");const { data: { user, errCode } = { user: null, errCode: null }, isLoading } =useQuery({23 unmodified lines};const openLoginWindow = async () => {setCurrentRoute(window.location.pathname);return router.push("/auth");};const loginFromCode = async (code: string) => {3 unmodified lines.post("/auth", { code }).then(async (res: any) => {if (res.data) {setCookie(res.data.access_token, {expires: res.data.expires_in? new Date(Date.now() + res.data.expires_in * 1000)5 unmodified linesuser: res.data.user,errCode: null,});if (currentRoute) {router.push(currentRoute);setCurrentRoute("");} else {router.push("/projects");}toast.success("Login successful");}})
app/api/auth/route.ts-11
app/auth/callback/page.tsx+44-12
hooks/useUser.ts+9-6