Answer the question
In order to leave comments, you need to log in
How to correctly organize authorization in NextJS?
Hello everyone!)
Just started learning NextJS.
In general: you need to hide all pages for an unauthorized user, and after registration, you can actually use the application normally ...
Requests to the database are made through axios. There is a separate API class with presets.
1) How to do it correctly, do a check in the _app.js component by the isAuth flag:
export default function App({ Component, pageProps }) {
const store = useStore(pageProps.initialReduxState);
const {isAuth} = store.getState().user;
return (
<>
<Provider store={store}>
<HeadApp/>
{isAuth?
<Container>
<Component {...pageProps} />
</Container>
:
<Auth/>
}
</Provider>
</>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question