Repository navigation
Best way to secure /admin routes #10724
Replies: 6 comments 33 replies
|
At which point do you have access to the authentication state? Then you could use the new redirect feature like this:
This way you have no added loading time and don't need to redirect clientside. |
|
Hey there, following the best practices from Zeit in @timneutkens comment here: #10724 (reply in thread) I created an example that follows those practices, see it here: https://github.com/zeit/next.js/tree/canary/examples/with-iron-session let me know what you think |
|
@timneutkens how would you do oauth in this situation ? i saw the solution you posted with SWR, but im now confused how would oauth based authentication work in this case - e.g. google auth kind of thing. others have asked this question in other places, DuendeArchive/identity-model-oidc-client-js#809 My whole site is SSR. |
|
Used the example they have given here:
https://github.com/auth0/nextjs-auth0/blob/master/examples/basic-example/pages/api/me.js
to
create an API endpoint, to retrieve the user info with a single fetch call
to /api/me. It can nicely be wrapped with
https://github.com/auth0/nextjs-auth0/blob/master/examples/basic-example/lib/user.js
for
convenience. I made some modifications to the code, but the principle is
the same.
β¦On Thu, May 28, 2020 at 8:48 PM Kinbaum ***@***.***> wrote:
@balazsorban44 <https://github.com/balazsorban44> Can you explain how you
actually go about retrieving the user session object? I am able to see the
user session information in the callback handler, but what approach did you
take to actually get that user information displayed on the page? All i see
from my cookies panel is an a0:state cookie.
β
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10724 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEMEVMLMKLTHNF4RMUE3KCLRT2WW3ANCNFSM4K5DEDDA>
.
|
|
https://github.com/nextauthjs highly recommended library which allows you to consume both popular(OAuth, google) and custom providers. with best OWASP practices |
|
One way you can do this is to create a layout which you use in all your admin pages and then in that layout do the permission checking. |
Uh oh!
There was an error while loading. Please reload this page.
Hi, so I'm slowly getting my head around sessions and auth with Next.js (deployed on Now). What I'm running into now is that I have a HOC
ensureAdminthat I can wrap a page with to check that a user is authenticated and actually an admin. (the API routes are secured ofc so it's mostly a UX/visibility thing). The downside is that you need to repeat this for every page.Is there a way to do this globally for everything under this path /admin? It would be nice to for instance have a custom
_app.jsthat applies to this folder+children or something.How do you solve this?
Should I just not try to limit access to the page and use a fetch hook to check client side after rendering the skeleton?
All reactions