I recently stumbled upon a fantastic tool for authentication: Clerk. Here's why I think it's a game-changer:
1. Easy Installation and Setup
By simply following their outstanding documentation, you can install the necessary packages and set up Clerk in no time. If you're using AppRouter for Next.js, all you need to do is wrap your entire layout with ClerkProvider
, and voila – instant authentication!
1<ClerkProvider>
2 {/* Your App's Components */}
3</ClerkProvider>
2. Out-of-the-box Login and Sign-up Screens
Gone are the days of building a login and sign-up screen from scratch. With Clerk, you get these, along with social media sign-up options, right out of the box. Just use their provided sign-up
and sign-in
components, set some environment variables, and you're good to go.
3. Robust Route Authentication
Through middleware, you can utilize the authMiddleware
to specify which routes are public and which ones to ignore. This means that any route that isn't public or ignored will require authentication – a feature that ensures enhanced security.
1// Using authMiddleware to specify routes
2
3export default authMiddleware({
4 publicRoutes: ["/api/documents/insights/1"]
5})
4. Access to User Details with getAuth
By importing getAuth
from Clerk's package, you can pass in the request object and instantly access the entire user's details. This functionality enables you to swiftly implement features like:
1const {userId} = getAuth(req);
2
3if (!userId) {
4 return new Response("Unauthorized", {status: 401});
5}
5. Exceptional Documentation
I can't emphasize enough how comprehensive and user-friendly Clerk's documentation is. From installation guides to detailed explanations of features and components – everything is meticulously laid out. Plus, the option to copy-paste components means you can achieve a lot with minimal effort.
6. User-Friendly Components
Clerk also offers components like the UserButton
, a handy UI element that lets users manage their accounts or sign out. The best part? You don't even need to build the sign-out functionality – it's all taken care of!
In conclusion, Clerk has transformed the way I approach authentication in my projects. Its ease of use, combined with its powerful features, makes it an invaluable tool for both seasoned developers and beginners. I've already incorporated it into several of my side projects over the past month, and I'm eagerly looking forward to using it in future endeavors.
Transcript
So, this is another tool that I'm really, really excited about, and it's for authentication. It's called Clerc. You install the packages. Their documentation is amazing, by the way. In your layout, if you're using AppRouter for Next.js, you just simply wrap the entire layout with ClercProvider, and you automatically get your authentication, right?
You get, like, things like this out of the box, which is insane. The fact that you don't have to build a login screen anymore, a sign-up screen. You get, like, social media, sign-up, et cetera. And all I really did was, I went through the documentation, they even give you this component called sign-up, one for sign-in, and you add some environment variables, and all of a sudden,
you have all that, right? Something else that's really cool is that, through middleware, you can instantiate what they call off-middleware, and you can declare what routes are public and what routes to ignore. So, basically, everything that is not public route or ignored will basically get locked
out in authentication, right? Which is awesome. Another really cool thing is that you have this thing called getAuth, which you import from their package as well. And through getAuth, you give it the request object, and now you have access to the entire user. So, you can do really cool things, right?
And this is just a very basic example, which is, like, okay, if there's no user ID, just respond that it's unauthorized and status 401. And that's insane that you could do so much in so little time. In the past, it would take me, like I said, days to build this, and now it literally took me, like, 30 seconds to install all this.
Another really cool thing is that their documentation is on point. Like when I mean on point, like, it's awesome. Just go through it. You know, they give you how to install the package. You have to set this environment variables in your .env, or if you're using Doppler or
like some environment variable provider, then you mount clerk provider by wrapping around your layout, or if you're using still pages, you know, you can wrap it around your app. And then it just goes on and explains all these things, right? It even gives you the components, like if you want to copy paste this, you did.
That's what I did. And because I copy pasted this, I got this out of the box. This is insane. And you know, again, you can even, like, set up, like, okay, what's going to happen after signing through environment variables. Like, that's crazy. They have this little cool thing, too, that I really like. It's called, like, the user button.
So it's like that little pill that has, like, manage account on top and, like, sign out and stuff. So you don't even have to build sign out functionality. Like, I'm so excited about this tool. I really loved it. I've used it for all my little, like, indie hacking side projects that I've built over the past month. And to be honest, like, I'm super stoked to continue using it.