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

Signing out a user #126

Open
JeroenReumkens opened this issue Apr 20, 2024 · 3 comments
Open

Signing out a user #126

JeroenReumkens opened this issue Apr 20, 2024 · 3 comments
Assignees

Comments

@JeroenReumkens
Copy link
Contributor

Hi!

Thanks for making this package! I'm right now converting my own very poor implementation of this to your package, and really liking it so far! Thanks for all the work you put in 🙏

I'm wondering if it's possible to also add functionality to sign the user out? Preferably by exposing a method we can use on the server to clear the session. A React hook as a second option would definitely be welcome too, although I like to sign out on the server most of the times (eg create a route /auth/logout).

Thank you so much! Happy to make a PR by the way, but might need some pointers on how / where to add it in that case.

@panteliselef panteliselef self-assigned this Apr 22, 2024
@panteliselef
Copy link
Owner

@JeroenReumkens Thanks for your kind words. Keep the feedback coming :)

Clerk already offers a signOut method client side, so I might build on top of that. For now you should be able to get access to that method directly via the $clerk store.

import { $clerk } from 'astro-clerk-auth/stores';

Probably a useClerk hook will come in handy for the react fans as well.

Regarding the server solution that you mention, are you looking for a way to simply fire a request from the client to your endpoint in order for the user to sign out ?

@JeroenReumkens
Copy link
Contributor Author

Thanks for getting back to me @panteliselef

In the meantime I indeed found the $clerk store. That definitely works great! I think exposing a small useClerk would indeed be very nice, which simply could return a useStore for the $clerk store. That's what I did on the client now, to be able to trigger the signout object from Clerk.

Until that hook is added I think it will be very useful to mention the $clerk store in the docs, since it gives a lot of useful methods you can use.

Server side

As for the server, I'd like something like:

---
const auth = Astro.locals.auth();
await auth.signOut();
Astro.redirect('/');
---

This way I can also create a page (/logout) which you can visit to also sign out.

@panteliselef
Copy link
Owner

@JeroenReumkens I've added signOut to useAuth. I'm reluctant on introduce a useClerk hook, how often do you need to grab the $clerk store ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants