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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@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, IdentityModel/oidc-client-js#809 My whole site is SSR. |
Beta Was this translation helpful? Give feedback.
-
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>
.
|
Beta Was this translation helpful? Give feedback.
-
https://github.com/nextauthjs highly recommended library which allows you to consume both popular(OAuth, google) and custom providers. with best OWASP practices |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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
ensureAdmin
that 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.js
that 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?
Beta Was this translation helpful? Give feedback.
All reactions