-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add auth & app/auth loading state; ssr fix
- Loading branch information
Showing
17 changed files
with
446 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { handleAuth, handleLogout } from "@auth0/nextjs-auth0"; | ||
|
||
export const GET = handleAuth({ | ||
logout: handleLogout({ | ||
returnTo: "/logout", | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NextResponse } from "next/server"; | ||
import { getAccessToken, withApiAuthRequired } from "@auth0/nextjs-auth0"; | ||
|
||
const GET = withApiAuthRequired(async function GET(req) { | ||
const res = new NextResponse(); | ||
const { accessToken } = await getAccessToken(req, res); | ||
return NextResponse.json({ accessToken }, res); | ||
}); | ||
|
||
export { GET }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
import { ChevronRightIcon } from "@heroicons/react/solid"; | ||
import { SupportIcon, ViewListIcon } from "@heroicons/react/outline"; | ||
|
||
const MyPage = () => { | ||
const router = useRouter(); | ||
const links = [ | ||
// { | ||
// title: "Documentation", | ||
// description: "Learn how to integrate our tools with your app", | ||
// icon: BookOpenIcon, | ||
// url: "https://openclimatefix.notion.site/Quartz-Solar-Documentation-0d718915650e4f098470d695aa3494bf", | ||
// }, | ||
{ | ||
title: "API Reference", | ||
description: "A complete API reference for our library", | ||
icon: ViewListIcon, | ||
url: | ||
process.env.NEXT_PUBLIC_API_URL + "docs" || | ||
"https://api.quartz.energy/docs", | ||
}, | ||
{ | ||
title: "Support", | ||
description: "Get help with any problems you encounter", | ||
icon: SupportIcon, | ||
url: "mailto:[email protected]?subject=Quartz%20Energy%20Support%20Request", | ||
}, | ||
]; | ||
return ( | ||
<div className="container flex-1 flex flex-col gap-6 py-24 items-center"> | ||
<div className="flex-1 flex flex-col gap-6 justify-center text-center md:text-left items-center"> | ||
<h1 className="text-4xl text-white">See you next time.</h1> | ||
<h2 className="text-xl text-white px-3"> | ||
You have been successfully logged out. | ||
</h2> | ||
<button | ||
className="bg-ocf-yellow py-2 px-3 rounded-md" | ||
onClick={() => router.push("/api/auth/login")} | ||
> | ||
Log back in → | ||
</button> | ||
</div> | ||
<div className="max-w-3xl w-full flex flex-1 flex-col gap-6 justify-center items-center"> | ||
<div className="mt-16"> | ||
<h2 className="text-sm font-semibold tracking-wide text-gray-300 uppercase"> | ||
More from Quartz | ||
</h2> | ||
<ul | ||
role="list" | ||
className="mt-4 border-t border-b border-gray-200 divide-y divide-gray-200" | ||
> | ||
{links.map((link, linkIdx) => ( | ||
<li | ||
key={`LogoutLink${linkIdx}`} | ||
className="relative flex items-start py-6 space-x-4" | ||
> | ||
<div className="flex-shrink-0"> | ||
<span className="flex items-center justify-center w-12 h-12 rounded-lg"> | ||
<link.icon | ||
className="w-6 h-6 text-gray-300" | ||
aria-hidden="true" | ||
/> | ||
</span> | ||
</div> | ||
<div className="flex-1 min-w-0"> | ||
<h3 className="text-base font-medium text-gray-100"> | ||
<span className="rounded-sm focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-gray-500"> | ||
<a href={link.url} className="focus:outline-none"> | ||
<span className="absolute inset-0" aria-hidden="true" /> | ||
{link.title} | ||
</a> | ||
</span> | ||
</h3> | ||
<p className="text-base text-gray-400">{link.description}</p> | ||
</div> | ||
<div className="self-center flex-shrink-0"> | ||
<ChevronRightIcon | ||
className="w-5 h-5 text-gray-400" | ||
aria-hidden="true" | ||
/> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MyPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,29 @@ | ||
"use client"; | ||
import Image from "next/image"; | ||
import Sidebar from "../src/components/Sidebar"; | ||
import Charts from "../src/components/charts/Charts"; | ||
import { | ||
dehydrate, | ||
HydrationBoundary, | ||
QueryClient, | ||
} from "@tanstack/react-query"; | ||
import { GET_REGIONS, getRegionsQuery } from "@/src/data/queries"; | ||
import { | ||
useGetForecastedGenerationForRegionQuery, | ||
useGetGenerationForRegionQuery, | ||
useGetRegionsQuery, | ||
} from "@/src/hooks/queries"; | ||
import { CombinedData } from "@/src/types/data"; | ||
import { useEffect, useMemo } from "react"; | ||
import useGlobalState from "@/src/components/helpers/globalState"; | ||
|
||
export default function Home() { | ||
const [combinedData, setCombinedData] = useGlobalState("combinedData"); | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
refetchInterval: 60 * 1000, | ||
import { withPageAuthRequired } from "@auth0/nextjs-auth0"; | ||
import { Main } from "@/src/components/Main"; | ||
|
||
export default withPageAuthRequired( | ||
async function Home() { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
refetchInterval: 60 * 1000, | ||
}, | ||
}, | ||
}, // | ||
}); | ||
|
||
queryClient.prefetchQuery({ | ||
queryKey: [GET_REGIONS, "solar"], | ||
queryFn: () => getRegionsQuery("solar"), | ||
}); | ||
|
||
const { data: solarRegionsData, error: solarRegionsError } = | ||
useGetRegionsQuery("solar"); | ||
console.log("page solarRegionsData", solarRegionsData); | ||
|
||
const { data: windRegionsData, error: windRegionsError } = | ||
useGetRegionsQuery("wind"); | ||
console.log("page windRegionsData", windRegionsData); | ||
|
||
const { data: solarGenerationData, error: solarGenerationError } = | ||
useGetGenerationForRegionQuery( | ||
"solar", | ||
solarRegionsData?.regions[0] || "", | ||
!!solarRegionsData?.regions[0] | ||
); | ||
const { data: windGenerationData, error: windGenerationError } = | ||
useGetGenerationForRegionQuery( | ||
"wind", | ||
windRegionsData?.regions[0] || "", | ||
!!windRegionsData?.regions[0] | ||
); | ||
|
||
// Get forecast data | ||
const { data: solarForecastData, error: solarForecastError } = | ||
useGetForecastedGenerationForRegionQuery( | ||
"solar", | ||
solarRegionsData?.regions[0] || "", | ||
!!solarRegionsData?.regions[0] | ||
); | ||
const { data: windForecastData, error: windForecastError } = | ||
useGetForecastedGenerationForRegionQuery( | ||
"wind", | ||
windRegionsData?.regions[0] || "", | ||
!!windRegionsData?.regions[0] | ||
); | ||
}); | ||
|
||
const latestCombinedData: CombinedData = useMemo(() => { | ||
return { | ||
solarGenerationData, | ||
windGenerationData, | ||
solarForecastData, | ||
windForecastData, | ||
}; | ||
}, [ | ||
solarGenerationData, | ||
windGenerationData, | ||
solarForecastData, | ||
windForecastData, | ||
]); | ||
|
||
useEffect(() => { | ||
console.log("combinedData updated", latestCombinedData); | ||
setCombinedData(latestCombinedData); | ||
}, [latestCombinedData]); | ||
|
||
if ( | ||
solarRegionsError || | ||
windRegionsError || | ||
solarGenerationError || | ||
windGenerationError || | ||
solarForecastError || | ||
windForecastError | ||
) { | ||
console.log( | ||
"error", | ||
solarRegionsError, | ||
windRegionsError, | ||
solarGenerationError, | ||
windGenerationError, | ||
solarForecastError, | ||
windForecastError | ||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<Main /> | ||
</HydrationBoundary> | ||
); | ||
return <div>Error</div>; | ||
} | ||
|
||
console.log("page solarGenerationData", solarGenerationData); | ||
console.log("page windGenerationData", windGenerationData); | ||
|
||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<main className="flex min-h-screen bg-ocf-gray-900 flex-row items-stretch justify-between pt-16"> | ||
<Sidebar | ||
title={"Rajasthan"} | ||
solarForecastData={solarForecastData} | ||
windForecastData={windForecastData} | ||
solarGenerationData={solarGenerationData} | ||
windGenerationData={windGenerationData} | ||
/> | ||
<Charts combinedData={combinedData} /> | ||
</main> | ||
</HydrationBoundary> | ||
); | ||
} | ||
}, | ||
{ returnTo: "/" } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.