Skip to content

Commit

Permalink
Fix redirectAuthenticatedTo errors (#3529)
Browse files Browse the repository at this point in the history
* Wrap BlitzProvider from next with RouterContext
  • Loading branch information
Zeko369 authored Jul 11, 2022
1 parent cacb65d commit 348fd6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changeset/moody-bags-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@blitzjs/next": patch
"blitz": patch
---

Fix redirectAuthenticatedTo errors
26 changes: 16 additions & 10 deletions packages/blitz-next/src/index-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {withSuperJSONPage} from "./superjson"
import {Ctx} from "blitz"
import {UrlObject} from "url"
import {AppPropsType} from "next/dist/shared/lib/utils"
import {Router} from "next/router"
import {Router, useRouter} from "next/router"
import {RouterContext} from "./router-context"

export * from "./error-boundary"
export * from "./error-component"
Expand Down Expand Up @@ -67,6 +68,7 @@ export type BlitzProviderProps = {
interface RouteUrlObject extends Pick<UrlObject, "pathname" | "query"> {
pathname: string
}

type RedirectAuthenticatedTo = string | RouteUrlObject | false
type RedirectAuthenticatedToFnCtx = {
session: Ctx["session"]["$publicData"]
Expand All @@ -92,20 +94,24 @@ export const BlitzProvider = ({
hydrateOptions,
children,
}: BlitzProviderProps) => {
const router = useRouter()

if (client) {
return (
<QueryClientProvider
client={client || globalThis.queryClient}
contextSharing={contextSharing}
>
<Hydrate state={dehydratedState} options={hydrateOptions}>
{children}
</Hydrate>
</QueryClientProvider>
<RouterContext.Provider value={router}>
<QueryClientProvider
client={client || globalThis.queryClient}
contextSharing={contextSharing}
>
<Hydrate state={dehydratedState} options={hydrateOptions}>
{children}
</Hydrate>
</QueryClientProvider>
</RouterContext.Provider>
)
}

return children
return <RouterContext.Provider value={router}>{children}</RouterContext.Provider>
}

export type PluginsExports<TPlugins extends readonly ClientPlugin<object>[]> = Simplify<
Expand Down

0 comments on commit 348fd6f

Please sign in to comment.