Skip to content

Commit

Permalink
Fix Page.authenticate not working for layout components (#3547)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandra <[email protected]>
  • Loading branch information
Zeko369 and beerose authored Jul 18, 2022
1 parent 54a66a9 commit 1c80909
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-adults-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/auth": patch
---

Fix `Page.authenticate` not working for layout components
8 changes: 6 additions & 2 deletions apps/toolkit-app/app/core/layouts/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from "react"
import Head from "next/head"
import React, { FC } from "react"
import { BlitzLayout } from "@blitzjs/next"

const Layout: FC<{ title?: string; children?: React.ReactNode }> = ({ title, children }) => {
const Layout: BlitzLayout<{ title?: string; children?: React.ReactNode }> = ({
title,
children,
}) => {
return (
<>
<Head>
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz-auth/src/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export function getAuthValues<TProps = any>(
) {
if (!Page) return {}

let authenticate = "authenticate" in Page && Page.authenticate
let redirectAuthenticatedTo = "redirectAuthenticatedTo" in Page && Page.redirectAuthenticatedTo
let authenticate = (Page as BlitzPage)?.authenticate
let redirectAuthenticatedTo = (Page as BlitzPage)?.redirectAuthenticatedTo

if (authenticate === undefined && redirectAuthenticatedTo === undefined) {
const layout = "getLayout" in Page && Page.getLayout?.(<Page {...props} />)
Expand Down
4 changes: 2 additions & 2 deletions packages/blitz-next/src/index-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Simplify,
} from "blitz"
import Head from "next/head"
import React from "react"
import React, {ReactNode} from "react"
import {QueryClient, QueryClientProvider} from "react-query"
import {Hydrate, HydrateOptions} from "react-query/hydration"
import {withSuperJSONPage} from "./superjson"
Expand Down Expand Up @@ -80,7 +80,7 @@ export type BlitzPage<P = {}> = React.ComponentType<P> & {
suppressFirstRenderFlicker?: boolean
redirectAuthenticatedTo?: RedirectAuthenticatedTo | RedirectAuthenticatedToFn
}
export type BlitzLayout<P = {}> = React.ComponentType<P> & {
export type BlitzLayout<P = {}> = React.ComponentType<P & {children: ReactNode}> & {
authenticate?: boolean | {redirectTo?: string | RouteUrlObject}
redirectAuthenticatedTo?: RedirectAuthenticatedTo | RedirectAuthenticatedToFn
}
Expand Down
5 changes: 3 additions & 2 deletions packages/generator/templates/app/app/core/layouts/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Head from "next/head"
import React, { FC } from "react"
import React, {FC} from "react"
import {BlitzLayout} from "@blitzjs/next"

const Layout: FC<{ title?: string; children?: React.ReactNode }> = ({ title, children }) => {
const Layout: BlitzLayout<{title?: string; children?: React.ReactNode}> = ({title, children}) => {
return (
<>
<Head>
Expand Down

0 comments on commit 1c80909

Please sign in to comment.