Skip to content
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

Component-level authentication #146

Open
ibagov opened this issue Dec 8, 2024 · 5 comments · May be fixed by #147
Open

Component-level authentication #146

ibagov opened this issue Dec 8, 2024 · 5 comments · May be fixed by #147
Labels
enhancement New feature or request

Comments

@ibagov
Copy link

ibagov commented Dec 8, 2024

Is there a way to authenticate client-side components at the component level, as opposed to the route level?

I have a modal form in my Next app which can be opened from almost any route, however the form itself is not associated with a specific route. Can I ensure that only authorized users are able to access it? Obviously, using the AuthKitMiddleware is not applicable in this scenario.

@PaulAsjes PaulAsjes added the enhancement New feature or request label Dec 10, 2024
@PaulAsjes
Copy link
Collaborator

If you're using server components, then calling withAuth within your component will give you either the user object or null if the user isn't authenticated. From there you should be able to either render a logged-out view or force the user to sign in (which you can also do by passing in ensureSignedIn: true to the withAuth call.

We're currently thinking about adding a way to do the above in a client component. Let me know if that helps!

@ibagov
Copy link
Author

ibagov commented Dec 10, 2024

Understood, thanks for the reply @PaulAsjes . So if I understand correctly, it's currently not possible to solve my problem using authkit-nextjs.

Do you think it make sense to try using workos-node for this use case?

@PaulAsjes
Copy link
Collaborator

You can if you're using a server component with withAuth. If you're using a client component then you can't just yet, but I'm currently working on a client side solution to getting auth. Hoping to have it released sometime next week.

@ibagov
Copy link
Author

ibagov commented Dec 10, 2024

Got it, thanks and looking forward to the solution! :)

@PaulAsjes PaulAsjes linked a pull request Dec 10, 2024 that will close this issue
@sergesteban
Copy link

You can if you're using a server component with withAuth. If you're using a client component then you can't just yet, but I'm currently working on a client side solution to getting auth. Hoping to have it released sometime next week.

I also faced the same issue while using auth on component-level, and I ended creating an extra context so I could make use of it. That felt redundant, tho I am glad to noticed the changes on #147 @PaulAsjes thanks

looking forward to it
cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

3 participants