-
-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[legacy-framework] Add authenticated layout support with Layout.authenticate
#2825
Conversation
Wow this looks really great! Just need a docs PR now |
One question: what happens if user still has their own |
@flybayer It will render the Layout twice, one inside the other. So, the changelog must acknowledge this and tell people to strip it from their |
I figured out a problem I didn't know until now. With this setup, the layout re-renders when the page changes. However, if I remove the |
What do you mean by this? |
For example, if there is a query inside that layout, it will run even if |
@JuanM04 ok so essentially with that approach it's not really adding any functionality at all, right? Can we expose some helper function like this to make it fully work? // _app.tsx
import {composeLayouts} from 'blitz'
export default function App({Component, pageProps}: AppProps) {
- const getLayout = Component.getLayout || ((page) => page)
+ const renderWithLayout = composeLayouts(Component) Not sure that's the best name, but you get the idea. |
@flybayer sorry, I got confused and it's hard to me to explain technical issues. Yes, this add functionality. However, there is an edge case (that existed before; it wasn't introduced by this PR): const Layout = ({children}) => {
console.log('Log from Layout')
return <div>{children}</div>
}
const Page = () => {
console.log('Log from Page')
return <h1>Authenticated Page </h1>
}
Page.authenticated = true
Page.getLayout = (page) => <Layout>{page}</Layout>
// logs from someone authenticated:
// > Log from Layout
// > Log from Page
// logs from someone unauthenticated:
// > Log from Layout When someone unauthenticated loads that page, the code inside Page doesn't run while the code inside Layout does. I wanted to mention this somewhere since writing (Note: forget what I said about the breaking changes, I updated the PR so you still need to declare |
Layout.authenticate
Layout.authenticate
Layout.authenticate
Closes: blitz-js/legacy-framework#349
What are the changes and their implications?
It allows for authenticated layouts. It searches the React tree returned by
getLayout
and uses the first component with eitherauthenticate
orredirectAuthenticatedTo
as the default. This value can be overwritten in a per-page basis with the already implementedPage.authenticate
Also, the layout is automatically rendered byBlitzInnerRoot
, because it can lead to unwanted behaviorFeature Checklist