- Podcasts
- CodingCat.dev Podcast
- Code with CodingCat.dev: Live Coding Clerk, into Next.js with James Perkins
Code with CodingCat.dev: Live Coding Clerk, into Next.js with James Perkins
CodingCat.dev Podcast
- June 30, 2024
- 1 h 19 min
- Episode 9
About this episodehttps://codingcat.dev/podcast/cwcc-0-9-clerk-with-appwrite
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
Code with CodingCat.dev: Live Coding Clerk, into Next.js with James Perkins
What up peeps, Welcome to Code with Coding Cats. Today on the show we have James with us. How's it going, James? It's going. How's it going with you? It's. Going well, I always forget. What part of the world are you in? So I'm in Raleigh, NC. So I think I'm in this Eastern Time zone, so that's nice.
So if people haven't seen me floating around. We were at Ng comp for a week and then came back and decided not decided we had it in the plans to go to Jamaica right after that. And I'm telling James it was hot. Like it was crazy hot. And we've been to, we've been to Jamaica a few times during the same time period and holy smokes, it was way hotter and more humid than it's been. So.
That's what we've been saying that all year. Like we haven't gone anywhere this year, but we've been saying all summer like, oh, it's way too hot here. Like it's got so much hotter than normal. And I'm like, we must be imagining it. We must be, you know, like when you've gone through the winter and you're like, oh, it's so, you know, whatever.
But like, yeah, they confirmed on the on, on the weather that like, yeah, it's like 20-20 more days or something, then over 90. And it's like, yeah, it's rough. It's. Just bananas. Yeah, it's, it's weird. I I keep reading about La Nina or La Nino and the Arctic vortex and I'm like, should be an interesting winner.
Yeah, yeah. I don't care either way. All right. So to jump into it, we're talking all about clerk today. And I just wanted to throw this up here because we had somebody on. Do you happen to know this guy? Yeah, I know this guy. Yeah, this is Braden. He's the other Co founder of of Clerk. He's a really nice guy.
And as everyone knows, we're gonna do 990 minutes of code and see where we can get I I'm hoping to play around with that right. But James tells me that it's probably not gonna work for now, but we'll see. We'll, we'll just try it out that way that, you know, my boss doesn't get mad at me either. Right.
Yeah. And and maybe we can investigate doing some other sync versions that other people do with other platforms that we don't directly integrate in so. For sure and just for everyone I know that hasn't heard I should hold up a sticker here I've got my sticker pack nearby. We'll, we'll go with this app, right App right went one point O today. So yeah, very exciting.
Do I love showing it off so I'm right in the middle of upgrader? I would show it off like right before we jumped down. It was terrible timing, but. That's the way it works. That's the way it works. All right, So what are we going to get into? Are we doing a next JS app or React app? Yeah, we can throw at me.
So there we go into my old web directory here get no not get cloned MP exits. Let's do this. Let's call it clerk demo. I mean, that's super exciting, right? Yep, that's about like 400 of those in my on my MacBook. Clerk Demo 1, Clerk demo two. You know all the essentials. Let's. See here. Hello everyone, M Huggins is out there. What up Mark I'm I'm hoping everything's streaming. Like I said, coming back from vacation. It's been a whirlwind man like right. I'm glad I had my my Mac studio just set and ready because I I've been running all over the place. That's crazy.
I I really want to get a Mac studio. I just. Don't. I just don't know. I don't know how I can justify the business expense this year, but I I can, I'll, I'll think of something. There's always a delicious write off somewhere. It'll. Right. Exactly. Exactly. Let's see, let's see code clerk demo open a new one. Why not?
OK, so we've got we've got this side of it. Do you want me to open any docs or anything or like the master? Yeah, I can be the docks guy. So yeah, the first thing you need to do is install our package which is at clerk slash Next JS. All one word. Yep, just like that. Cool. That one's nice and easy. Maybe, maybe we'll go this route, maybe people will be able to see it.
There you go. We'll try that. If I if I gotta jump up like this, we can do that too. OK. So that that's the only package you need for clerk and then we need to go to the clerk dashboard clerk. Dashboard. If you just click sign in or sign up doesn't really matter. I think I got a clerk thing somewhere out here.
We'll find out. No, that's good. That's good enough. OK, So if you click add application and then you can name your application whatever you want. And at this point, you get to decide what social logins you want to use, how you want users to sign up, all those kinds of goodies. Oh. You have a meta mask login.
That's we. Do yeah. I'm gonna, I'm gonna click that one. We'll see how messy it gets. Yeah, that's. Fine. And then, yeah, if you're happy with that, just click finish. And then at this point you're basically ready to use the product. Yeah, we, we love a bit of confetti in our in our line of work. So on the left hand side, you'll see there's API keys under developers and you need, you're going to definitely need the front end API key, which is perfectly fine to show on stream.
It's just the client side. So let's start with that. So let's create a dot m.local and it's going to be next under score public, under score clerk, under score public, under score clerk, under score front end and then under score API. And then just drop that in and hit save. That's what we're going to need for now to get all set.
Yep. We'll also import a couple of other components. So we're going to import signed in, signed out, and we'll also import sign in. Yep. OK, cool. So before we go any further, I guess I should explain what all of these do. So people understand the clerk provider is something you wrap your whole application in and this allows you to essentially handle state in some in some way handle the off state. So yeah, go ahead and feel free to wrap your application in that.
Then the other ones are essentially based upon the state. So we have two components here, signed in and signed out. Sign in allows you to wrap some part of your application in it and that will essentially say hey if the user is signed into clerk, go ahead and show the screen otherwise the signed out version will show a different screen. So we can use our app dot JS here. I'd need something real quick.
It's kind of driving. Yeah, go for it. Here we go. Fixed. Boom, good. Perfect. So if you wrap that component like the main component in the signed in so. Above the provider. No, inside the provider, OK. Yep, oops, signed. You ever wonder like non-english speaking people are like what the heck is the difference between?
Yes, yeah, I, I worry about that sometimes. But everything's in English, right? Almost everything that's in that. So I imagine at some point you you read the docs and figure it out. It's it's really hard to program I feel like, unless you know English right? I used to have a a gentleman way back in the day who wrote all of his variables in French and like all of his functions in French.
World, right? I rock his world and I believe the answer is yes, but don't quote me on that. We can we can bring up some documentation if we have time. But we can dive in. Yeah. And we can ask developers. I probably have. Well, they might be asleep by now. They're all in Greece, so they might be asleep.
Oh my gosh, do you get to go to Greece? I haven't been yet. Colin and Braden are there right now. Wow. So bring me back some olives if you go. If I go, I will 100% do that, yes. And then we can wrap. So underneath the signed in, we can do signed out, which will basically Nope underneath it completely. So yeah, as a separate one.
So this basically has two. And then inside of there put the sign in component, the very last one. There we go. Oops. And Yep, and and that can actually just be a self closing tag. It doesn't have to because we're not going to put anything in it. And that's it. If I'm understanding this right, our entire application we are going to say if you're signed out, throw up the sign in, otherwise show us whatever component page we're on.
Exactly. The fun thing about this, and if it works correctly, I assume if we were to do any server side rendering, it's always going to have that sign in on there first, correct? So if you use SSR, we at Clerk we actually have a different way that you can handle redirects. Otherwise, what may happen is Clerk will attempt because it's on SSR, it will attempt to do something and the user may not be signed in. So then you have to handle that.
So instead with SSR we can actually look in the context and if there's no user, we'll just throw you to the sign in Page. So we have a couple of different. Ways to like handle it? Check that out in a minute. Yeah, SSR is my favorite. Like of all the ways to do clerk stuff, like I pretty much use SSR solely.
OK, so we're basically ready to go. So you can run NPM run dev and then if we go to local host 3000. All right, So at this point we're authors set up. That's it. We're we're we're good to go. There's nothing else for you to do in theory. Now you can run your application and authentication is is done. Can I can I click log in and try it out? Yeah.
Go for it. Sweet it. Should the SSO? Oh, interesting. Blah blah blah failed the fetch. Try again. That's an interesting error message from SSS callback. That's a fun one, isn't it? Just try. Just try refreshing the local host again. OK, I've never seen that error message before. Interesting. I'll have somebody, at least I have video evidence. This is what I like about live streams, right, Because I have video evidence of things that weird things that happen. Yeah, write that down and then we'll do that. OK, so in theory, you're signed in right now. And so we can actually add one more component to the screen that'll allow the user that's signed in to manage their account.
So underneath the signed in, but above the component prop, Yep, just here do user button. And that could be self closed as well. And if you go back to the app now, you'll see there's a little button up there and now you can manage your account, sign in, sign out. If you click manage account, it will bring you to a modal where you can literally, yeah. And this is all built into clerk. So there's no work for you to do is a whole 100% built in and 100% customizable.
So if you don't like the colours, the shape, the look, the feel, the text, whatever, all of that is completely customizable and in code. So if you're using, so if you're using Tailwind for example, and you have a theme already, you can essentially apply that theme to Clark and Clark will just take all of those colours and start showing them on screen.
That's really cool. Yeah. So this screen essentially allows you to do a bunch of stuff you can. I would stop about here in case you want to don't scroll further down. Your IP is there just just as an FYI, in case you're concerned about exposing. Your IP. Yeah, exactly. So here you can like add your a new e-mail or you can connect another account.
You can add your web three wallet if you're using Web 3. All those kinds of things can be done nice right from the screen. And one more thing to show off before we do like any real work. If you sign out of the account. So if you just click off and click there and click sign out, if you if you attempt to log in with your same e-mail from Google in the e-mail address.
Field. Sorry, should have explained that bad. Yeah, in the e-mail address field, if you sign in through here, what we'll do is we'll send you a verification code to your e-mail, which you don't have. If you can find it, great. If you don't, that's fine as well. Essentially what we'll do is we'll link those accounts together. So as a user, if you've forgotten that you've signed up with Google or Twitch or Twitter or whatever your social provider is, and you're just like, oh, I must have used my e-mail for this.
If you type your e-mail in, we'll just go and attach that to your account. That is really amazing because I find that like those two pieces the most frustrating when I'm dealing with like Firebase authentication, especially like when someone can't remember what you'd login, social login service they used and then they're like throwing an e-mail in and it's a mess. Yep.
And, and, and it's, there's nothing worse than a user signing up for a new account because they're like, I swear I use my e-mail address and they actually use like Google author or whatever. So we have that as a feature. Automatic account linking is free. It's, it's on the free tier. So even if you're just playing around the the platform, it's 100% free and it takes that burden away. We should check that for a minute. So let's see if let's see here clerk.gov, let's check out the pricing.
Yeah, it's there right on the right hand side, pricing price of four docks. You guys are using this like unless it's my monitor this wild, like almost paper looking background. It's really cool. I don't know what that is. Yeah, yeah, we are on some pages like on the hero and stuff where anything that's white, yeah, it's it's like a papery. That's so cool.
Although this is about to change, so don't get too attached to this. Everybody or the home page is about to change and it looks 10 times better than it does now. Should have delayed this whole pod. Great. One more week, right? I should have delayed it one more week so I could show off the new home page. It's all good.
So so right now we're on the free plan. What? What does it mean to go to hobby? You're getting SMS auth it looks like. Yeah, so there's some extra things. Allow, allow lists and block lists. So you can allow only like, you know, clerk dot dev, they're the only people that can sign up for your, your thing. You can customize all the emails and all the SMS messages. You get to remove that little clerk tag that's in the left hand corner of a component and then SMS auth. And the only reason SMS auth has been moved out of the free account was because we found a lot of people were using SMS auth for like spamming people.
Yeah. So we moved it out of the the, the sort of free tier into that. Yeah, it's just been hard on the reason free items like preventing all of the misuse of it. I so I see this .02 Mau but then as starting at 49, so I assume it's $49 plus the active users or what's that look like? If you yeah, so it is it is 49 nine dollars a month I think is the minimum.
So we charge that minimum and I think there's a rate to how many miles you get, but I. Can't. I got you. So you would have to add up to. Right. Yeah. And then it goes up to business where it starts at 200 and and you know gets a bit more higher and higher. And higher. That seems really reasonable to.
Who is this is interesting. So transactional emails that's just for like your your code that we just sent out and probably like password change and things like that. Yes and no. So yes, but also no, because like things like things like password resets, you know, magic links or OTP links, things like that, those are all included in this verification slash invitation emails.
What are all the things I can get rid of? All of it. Just get rid of anything that's Firebase off. Just put in clerk. We'll I'll help you out. So here's here's a huge question. I have a bunch of users on Firebase. Can we use those? Like what's that process look like? Yeah, so we can actually export users from Firebase and put them into Clerk without the user actually knowing.
So you're you'd have to like essentially convert services though at some point. Yeah, yeah. At some point you'd have to convert your auth service from one to the other. But we offer like we actually have documentation that shows you how to do it and the script and everything that comes along with it.
So to try and make it as easy as possible to to switch from one to the other. And if it's more complicated than a simple auth switch, like we have people to help if you see, which is just me probably. So it's me, but yeah, so I'm. Pricing springs directly. Yeah, just call me, send me a Twitter DN any. Time of day.
Yeah, any time of day, you won't get an answer after about 5:00 PM, but you can try, Yeah. And then we have offerings for start-ups too. So like if you're a start up, there's pricing can we can give you like six months free and some other stuff too so that you can scale your business 1st and then worry about it later. Nice, cool.
Where do we head next? Like. Well. Off like how my username ended up in here. Yeah. So if you go to users in the top. Users. Yep, you'll see there's your your coding cat. And if you click on it, you can click on view profile. Just click on it, either one, and you can see that there's not a separate account for that first one. And you can see that your e-mail address and social accounts are exactly the same.
Gotcha. So none of that has changed you. You're good to go in in that sense. But if it was a different e-mail obviously, and we couldn't match them because let's say your Twitch account is a different e-mail, obviously those wouldn't be linked. But users can link in other ways. So from the user profile, like if your web three wallet is obviously doesn't have your e-mail address attached to it, you could add it from the user profile screen and it will get linked to this account automatically.
So that even if you signed up with a web three wallet, it would be the same one. It would have your other emails and everything attached to it. Sweet. Tell me more about this metadata down here. Yeah. So we have three types of metadata at Clerk. There's public metadata, private metadata and unsafe metadata. Each one of these can be accessed in different sections of your application and updated in different sections. So public, that obviously can be updated on either the front end or the back end.
That makes kind of sense. Private can only be read and updated on the back end and unsafe can be read on the front end and the back end, but only updated on the back end. So if you need something like a good example is like Stripe, like a Stripe account ID or whatever, where you've they've made a payment, you could have put that in your public metadata, have access to it somewhere on the account.
So you don't have to make an additional call to your database to see, oh, this person does they do they still have X or Y or have they paid their one time fee or anything like that? You could handle that all on. On this side, nice. Trying to save you a bit of like to Firebase's custom attributes as well. Right.
Yeah, same idea. Awesome. All right, where should we head next? Yeah. What should we, I guess we should talk about customization. Yeah, so, so there's this option here. So Clerk gives you two different ways to essentially have the signing components. There is the hosted version which is 100% hosted by us and it basically redirects to a URL and then you just type in and then it re decks back to your application or you do like the mounted components, which is what we have in our application right now. So anything that's in this section here under branding or themes, etcetera will be done for the hosted components only. So if you have the mounted components that we do, all of that can, all the customization is done in the code, OK, but we can show this off real quick.
Branding, obviously you can add your logo and your icons, you can upload those. And then under the theme section, there's a really basic CSS theming. Just sets a few colours, a few fonts, all those kinds of things. And then those will get updated as soon as you click apply change to the hosted components.
Oh you guys need a search on here. Can I add that to your request? Yeah, yeah, I'll, I'll, I'll put it in. I've thought that too when I first first started. Like there should be a search here, you're right. Or or at least a way to to flip through them really quickly. I don't think my new Nito is not on here. Bummer.
Probably it's a very limited amount, but if you click apply, we can actually show this off. So if you click apply and if you scroll up on the left hand side, we give you component previews where it says sign up up a bit further to the left. Yep, you're just on it. Yep. Those If you click that, Yep, and then just click sign out, you can see that all the colors have changed now.
Now it's purple. So for your hosted component, it's a media. As soon as you make those changes, it's a media. You don't have to worry about code, you don't have to worry about themes, etcetera, etcetera. But if we're to come out to this version. As you can see, still the same. Yeah, cool. Because it's because it's on your machine. We have this appearance property and this appearance prop can change basically anything you see there. You can target in some way and we can quickly show that off before we get into like hardcore APIs and all that kind of stuff. So if you go back to the code, so in your, you have a couple of options here.
So you can hit it directly in the clerk provider or we can hit it in the sign in component. So we'll do the clerk provider because I think it's just easier and cleaner. So the property is called appearance and then you want to put a double set of parentheses around it. Yep. And then if you do layout, that should be one and then do it's an object.
So you can do another set of parentheses. Yep. And then you should get Intellisense if you do command and whatever it is control enter or. I always messed up. Whatever the whatever the VS Code is maybe not let's do check we'll just go here Scroll down. Oh we can do it directly on the sign in component. Let's do that instead so go back Yep and do sign in instead of layout start with sign in so appearance prop stays the same. Oh, OK, just the layout.
Just get rid of that for a SEC and we'll do sign in. There we go. Oops, it's. Yep, you got it. And then inside of that we should now have Intellisense, I think. Apparently not. It might be my machine, I'm not sure. Or it could be that we're missing types. Actually, that's probably what the problem is. We probably didn't install at clerks slash types. Oh OK.
Usually it complaints about them. Surprised. Yeah. Yeah, you can install the types if you wanna shut the local host down. You should just. Be at clerk slash types. Oh, you probably. Can't see. I can't see. Sorry, sorry, sorry. Yeah, that's the one. And while you're doing that, I can pull up my in case for some reason types don't work. I have some many different clerk demos that have all sorts of customization.
It acts like that's like a generic or something, I don't know why. Sign in. Yeah, interesting. What we can do, we can do it without. I have the I have the brain power, he says. All right, so let's start with, let's just do something easy. Let's do elements so. Yep, now it's it's funny, as soon as I started.
And then you can also do like BG color or background color. I think it's probably background color, yeah. And then give that whatever color you want. Maybe we'll just stick with white. I'll I'll make it green. So it's obvious for now, but. There we go. And then if you just hit save and then go back to the code, oh, there you go, it's already changed. And it looks rough.
So yeah, it looks rough right now. That's fine. It looks about as good as all of my designs. But yeah, so you have the ability to essentially hit any form element that we have. So that's option #1. Oops, sweet, I love it. So yeah, there you go, nice and purple. But for example, you may want every single color background to be a specific color, right? So maybe you want all your backgrounds to be yellow so you can actually hit something called variables instead. So if you go back to the code and underneath your elements, if you just do another object called variables and then we can just hit color primary and that will be primary color of text. So you might want to choose a different color just to show it off.
You can type in literally red. Yeah, I was going to say red literally works every time. So you can see like this sign up little down here where the link is. That's the color primaries that's changed. And if you go back and we do color background as the next one and you just do whatever color you want.
I like yellow or purple. Yellow's good, yeah, And it's amazing blue. Yeah. So yeah, real break. But you, you obviously if you signed in now and went to the user profile, that background yellow would also be there as well. So if you quickly sign in and click the use button and then go to manage account, no it won't because we did it in sign in totally like. All right.
I'm so sorry if you've done it, you could. Yeah, you can actually just pull all of those elements and the variables out or the variables out and just put it underneath and that will apply it globally in the appearance property. Here. Yep, yeah, there you go. So so you have options on how you can style and every element you can pinpoint and change. You can do it specifically for each component or just do a worldwide like every element that has this name. I want to be green every element or variable once. This is this like CSS variables under the hood? So we're using CSS?
You probably can't see it very well on stream. Might need to bump up the console. Plus Sir. If you see there is like CL internal something, something, something and then there's one next to it another class like CL NAV bar. So the NAV bar is actually the element. So you can actually hit just NAV bar in your elements and that will change the NAV bar or scroll box or page or whatever you pick. So that's how you can find out which elements you want to hit, which makes it really easy.
So we've really made it as easy as possible to to, you know, make your brand and Colin and I, Colin is the Co founder. We've had some fun with it. We recreated the Reddit login page. I created the Skillshare login page. Like we've been having fun just rebuilding, you know, different, different kind of things.
And you can actually see much better designs in our documentation if you go yeah, to that one. If you go to products and go to, there should be like a customization under the components section. And if you Scroll down a little bit and so you can see these. And if you click on them, these buttons, light, dark, simple wave on the right hand side. We actually give you the way to create these yourself if you so wished.
That's really cool. Yeah, we we did some cool ones. That one's wild right there. Right. So, yeah, so there's a lot of customization that you can do now. This didn't exist three or four months ago. And we tried to make it as easy as possible to to get started. Yeah, I love this. Is there any JavaScript that has to come across when you actually load this? Or is it all within the components already? Is it just like API calls once you log in? So for the appearance prop, yeah, yeah, yeah. So that's all done with the component itself. Cool.
Yeah, yeah, this, this one is completely shakeable. So it doesn't add any extra like kilobytes or anything to your to your project. So love it. Yeah, this is really cool. Man, I'm so glad it has been so long since you've seen this. Yeah, it really has. Before it was kind of like I don't, I don't know like this is OK. But obviously they had grander plans, so. Yeah, it was very easy.
So I anyone that doesn't know who I am, so before I worked at clerk, this is this is me. I used clerk for over a year in every project. And I was one of like the first people whoever like really spoke to them about certain projects and stuff like that. So I've seen it grow from this, like this is so cool that I can do this really quickly to this is so cool. I can do this really quickly.
And now it has all these extra features that like customizations and and things like that. We have like localization coming in like a week. So you can translate everything into the language, native languages of of choice. Yeah. So it's been crazy to see all that. And now that I work there, I get even more excuses to talk about it all the time. So before I just talk about on my YouTube channel all the time, now I get to do it for a job.
Yeah, it took me 12 hours from being let go to sign the paperwork for the the new role. Which why I'm why I'm discussing this. It's not like a dig at James or anything when he's working with like clerk and open source. That is kind of the way for those who are looking for jobs kind of coming up, jump into an open source project.
That's who we hire from at app, right? When we are looking for people. If you're like in our repo already, you know stuff and you're contributing, there you go. Like why wouldn't we hire you so? Right. It's it's a lot easier to be like, hey, like you already know who I am. I'd really like a job there And like it cuts down on like interviewing and other things because they already know you have the knowledge.
Yeah, exactly. So for those new devs out there, just think of it. I I know it can be extra work sometimes, but if you're passionate about something, go for it. Yeah, yeah. And usually you can even if you don't want. It doesn't work out there. People that see you kind of contributing to an open source or helping the community or something will will, you know, try and help you level up or, or find the right people to, to get jobs.
Yeah, We can attest that we run our documentation from it. So I mean, it works. It's. Interesting. I'd be curious for your like APIs and stuff. Ours are actually in the code. So we we produce all of our documentation directly out of the code. So it's always up to date. And that was that was something new.
Yeah, so we doing that right now. So we're, so we have two types of documentation. We have reference material and then like other kind of stuff like getting started guides or like stuff that's not referenced. So our reference material is about to do the same thing where we're using like open API to like create the documentation for us.
Right now it's a complete manual process. We have to have our devs like go in and make the change and do that kind of stuff. But yeah, in the future we're going to do the exact same thing and then we have a new hire starting on Monday who's a good friend of mine who is going to be doing the helping me with the documentation.
So we're going to need to add in the Clerk API key and we're probably going to want the JWT key as well. Both of those shouldn't be exposed on stream. So I don't know if you can it's. Fine, I'll probably tear this one down anyway, so that's. Fine, then go for it. I'll show you where they. I'll show you where they are in the in the dashboard so that you can get them.
Oh, that, that did not do I expected I guess the comments OK. Oh yeah, that's weird. That should not happen. That's what we'll find out. Let's see if this actually works. OK, yes, show me where these keys. Are so back into the API. Keys at the bottom should be on the developer's left hand side, just gonna near the bottom.
And then if you just click show key on the default and then you should just better copy that. So that's the that was that was pretty good. That is the Clerk API key. Let's see if this works. Let's see what was in there. Oh, that got real weird. Yeah, that got weird. And then the other one is clerk under score.
Yeah, just copy the JWT verification key. It's on the all the way on the right. Yep, and that one is just clerk under score, JWT under score key and then just hit save. All right, cool. And now with next JS you don't have to reload anymore. Oh, really? If you make changes to your your dot emvs like you don't have to reload anymore.
I did not. Know that it it's new for 12.2 or 12.3. Nice. We might have to. Super great feature. That's that's really cool. OK, so now we're ready to essentially use. If there's an error there, I can't see it just as. An effect? Yeah, it's an error, but it's a web pack weird thing, so we just know if that's. Failed to fetch.
Interesting. Yeah, I, I blame that on next year. That looks like. Yeah, that looks like a next year's problem. I think we're OK. We'll blame them. Cool. OK, So if we go back to the documentation. Yep, we can Scroll down pretty far now. I'm gonna try to do this. We'll see how this goes, so I'll put us back.
So everything else can get rid of that. Perfect, perfect. Sweet. And then if you Scroll down. So that page props part is what makes SSR possible. We basically tap into that context so we can have access to anything in the context. Makes it really easy for SSR to work and it allows you to do some some. Basically I use so I also have two sasses if you don't know, and one or both of those sasses use Clerk and both them use SSR under the hood.
You guys name them now? So I've got cross poster which allows you to cross post your blog posts to dev 2 and hash node from your own blog. And then I have Roll your Tweet, which allows you to take a tweet, roll it up and make a blog post out of it. I wasn't. I wasn't aware of the first one. Like that's pretty new.
I was. That's. Pretty fun because I just wrote an article how we do pub sub functions now to push out to hash known dev 2. There you go. See, I just, I allow people to do it right out of the gate. It's pretty, it saved me the whole weekend. Right, It's pretty neat. I, I use it all the time for my personal blog.
So it just makes it was I basically built it for myself. I didn't care if anybody else ever like used it. So I was just like, I'll build it for myself. That's awesome. So now we can essentially protecting pages is what we want. So we don't have to worry about controlled components anymore because these render on the front side, right?
So in the front end, those components render so you don't have to worry about these. So if you Scroll down a bit further and keep going using server side, here we go. So essentially I'll kind of explain this documentation at the same time, but essentially what you do here is you pick a page, whatever page you want to protect with SSR.
And what we do here is we look to see if there's a session ID in our requests. So if it doesn't have a clerk session ID, you can force the user to to essentially sign in. Otherwise you can let them in and they can do whatever, or you can go and get stuff from your database or whatever you want to do. So this is a really, really basic example. The only thing that we're going to want to do beforehand is. I'm not sure why it's complaining about being overloaded with server side off request resolved URL. That looks right.
Yeah. TypeScript just. If you do it in JavaScript, it's never going to complain we. Could we could just do the old? Yeah, you might be able to just do the dot, the any, but let's make sure that we return a page as well. OK, so we have blah blah blah props return. I don't know why we're just returning. Oh, this is the server side.
How about? Yep, and then you'll probably have to import the next page, yeah. Definitely doesn't like some things interesting. We're going to we're going to just cheat and make this much simpler. Yeah, oh, because it has style, it has modules for CSS as well. So if you get rid of that class name, then you should be. What are you complaining about?
Oh, because you need to get rid of. Get rid of the full class name first. So get rid of that whole prop. Yep, that should get rid of that. Problem and then. Don't need that, and then we'll worry about the overload problem in a minute. OK, so before we go any further, there's a couple of things you need to talk about.
And then inside of that, we're going to use two square braces, dot dot dot index. Yeah, with the square braces around the word index, not around TSX. And it's two square braces. Oh yeah. So it's like it was getting broken. Yep. So this essentially is just a catch all route and somewhere in our documentation I think if you scroll up maybe or down, maybe it's down.
Let me look at my own documentation. This is how we do developers documentation. There should be a discussion about how to do this correctly. Let's see, I could just use the search functionality I suppose. Component using Clerk's components. That might be it. One second using Clerk's component, I forget. This is the only thing I forget how to do every single time. Let's see.
With 12.2 they were just like, sorry, we didn't tell you. OK, so the page should be apparently I don't use it here. I guess we could just redirect one second. I'm looking at my own code because I can't remember where it is in the documentation. Yeah, I know Auth 0 does something similar, so they have their own components.
So you're not redirecting, but if you just turn this I can send this to you right through somewhere in here private chat. Discord it to me if it's long. It's not that long. Try that and I can explain this at the same time. Let me know if you got that. Got. It and then you're going to need this part too.
Oh, I see. This is in app dot JS. That goes in that in the SSR itself. So go to the projected route. We actually don't need the sign in Page at all. Now I've decided we'd go in a different route changing, changing so we can use the mounted version. So if you didn't want to self mount, you could use these two things here.
So the redirect I just sent to to to Alex here and then the redirect. I also just sent you another message which you can just stick anywhere. It needs to be inside there, so Yep. I bet. Yep. OK. So let's just quickly talk about these. So what we're doing here for the destination is Oh yeah, is we're telling it the front end to go to this page. So essentially it will just take you to your component that is map hosted by Clark versus having to to self map your own component.
It's up to you. Yeah. And that would just be local localhost 3000. And then the front end URL is just the API key, the front end API key, but with HTTPS in front of it. So it knows where to to resolve it to because it doesn't for some reason in SSR it doesn't add that correctly. So you end up just in nowhere land and it doesn't do anything.
OK. And that that should get you exactly where you want to go. OK. So we can we can pretty much test this out at this point. If you go to that page now, I imagine you're probably still signed in. So yeah, still signed in. So if you go to the dashboard. Oh, OK. We can go to. You can either delete the the user, that's fine, or you can just click the sign up, sign in component preview there and it'll ask you to sign out.
Perfect. There we go. And then if you just refresh that page it should just 04/04 not found. That looks like the right URL. Clerk equipped monkey. Just make oh maybe go to the dashboard. Maybe I typed it in wrong. Yeah, that is the go to component preview again. Just click the sign up sign in. Did I type it in wrong?
Oh, it's accounts. OK, yeah, so it's got the A word accounts in it. I'm sorry about that. I forgot we changed that. No words. So it's https://accounts.yepandthen and then. So now if you go and then just do like a back and then go forward to protected, now it should go there. And then if you sign in, it should redirect you back to that page, assuming that we typed in the URL correctly. Maybe there's something with your off callback that doesn't seem to want to work with Google. Try.
Yeah. If you go to the projected page now, does it say protected? Yeah. So some sort of weird Oauth call back from when Google sends it back doesn't work properly for some reason. Yeah, let's try I've. Seen that before? Let's. See what happens? I'm kind of curious. Like what? So at this point what it sends us to so it actually bounced into protected. So it made it all the way through the Oauth. Did we put HTPS or HTTP in front of that local host by chance? In our rearable?
No. Try putting HTP HTP slash slash. Yeah, that. Let's see if that fixes it. Cool, back out. I could just be bad at code. That's possible. Great HP. Oh yeah, you go. I'm just bad at code. Yeah. No, no, it's bad at code. It's. All good, It's all good. These these are like the lessons when people's watching this.
If you look at the documentation again, we actually have a way to access the user data of the user in your SSSRSSR route. If you Scroll down further, there should be enabling full server side rendering. There it is. So what we do here is we use this load user true, which, yeah, you can see it there like inside of that, if you do load user is true, what we'll do is this adds an additional one network request. And all it does is if there's a session and they're logged in, we'll return that user data that you can then use in your application before you show them the page. So if you need that user ID or, or something similar, you can essentially grab it and be like, OK, I've got the user ID, maybe I need to go and get a bunch of stuff from my database that has this user ID attached to it.
You can then return those as props of data. So you don't have to do it on the client side after the user's logged in. So you could do it all full server side running. This is what I do in my application. It just makes life so much easier. So the way that you do it is, yeah, you just add. We can actually just pull that whole thing if you want to just copy.
And paste that, yeah. Do we need the not session for the redirect still there? We'll just assume that we're. You will need that if you're going to keep the redirects too, so you'll want to keep that in, but you can copy and paste the feels. Like we just need. This yeah, that's all that's all you need.
Yep, OK, which goes right between the yeah, there here. Oops, Yep. And then we can actually pull that in somewhere in the in the code. So if you do like after the if the session ID, right. So if under session ID, after that we can do construction. User ID equals request auth. In fact, if you do a console log with request off, you can see what's inside that, which is probably more interesting than doing just the user ID.
Yep, we see all the cool things that are inside of there. So yeah, you should be able to just refresh the page. OK, so inside of here is a full JWT which obviously you can use. You've got a user ID that then you can then use like some of our handlers like we can get an e-mail address, we can get different pieces of the user. And then this get token is the special source as I like to call it.
And then click new template. So these are the ones we integrate with right now. We've got fauna N host graph based Azura Superpace or a blank one. If you have your JWT that you can use, you can use a blank one if you just click on, I don't know, N host, I guess, or Hazura. Those are usually pretty easy.
This gives you like an example of what the JWT will look like, and these are the things that you'll send to end host with that JWT. So in this example, there'll be a user ID, the default role, and then you can add extra things. If you need the user's first and last name for some reason, you can add those as short codes and we can use them.
I even imagined it or I saw an open issue for it. I like the imagining part. That's yeah, you know, when you're just like Googling stuff and you're like, I'm pretty sure. I think I saw that so. Yeah. Yeah, closed. What's that? Oh yeah. So there's two, there's one that's closed, and then I think there's an additional one that's open.
Yeah, like there's a duplicate ticket somewhere. Duplicate. Yeah, there you go, Validate JWT on external API back ends 'cause right now you you can't do that. And what what the other person was asking for is like, hey, if you have the JWK URL, we can essentially do that. So that's what our JW TS do. So we go to the provider, let's say it's end host, and they have an option to override that in the application. So we paste in the clerk JWKURLS so that we can then say, hey, we can verify this JWT and make sure it's legit. And then you can essentially do the rest. It's one of my favorite features. If you don't for some for some reason if you use a project that doesn't have it, like my projects use planetscale for example.
So for me I use planetscale. They don't have like. There's no token based API, so I use the user ID to fetch my data. And that would just be the standard code. There we go. So you would receive. This, yeah. So I use that. So I have that inserted into my database somewhere and I can use that to reference whatever I need. But yeah, so those are all different options that you can use this with.
Is there this is how bad I am with the authentication? If if we did add the JWKS endpoint, is our authentication layer still going to be owned by Clerk then? Like all the user management, all that stuff. Yeah. So that's essentially what you. Yeah. So instead of using app rights authentication, essentially what would happen here is the user has decided they want like a provider that has maybe more features or or whatever it might be, more options to log in, something like that, right? They can use us.
And essentially that would take care of all of that, which some people may or may not like. I believe in the future there may be an option for us to use the Oauth two kind of like Auth 0 does right now. I know it's probably on our radar. That's kind of what I was wondering, like if we could swap out instead of auth 0 here, have clerk as one of these and then we'd be golden.
Yeah. And then and and then you know, that gives you extra leverage everywhere, right, Because there's probably providers that you have that we don't have and there's providers we have that you, you guys may not have or the customization somebody wants or they already have clerk and they're moving to app, right, all those kinds of things.
That's really cool. Yeah, it's, it's definitely cool that you can use SSR. It's probably one of my favorite things. And we could do more here, right? So we have the user ID in theory. Now we could go out and use some of the clerk's handlers to like get information. Yeah, I'd love it. I mean, we have another 20 minutes if you're still available.
So I sent you a bit of code here, and we can just drop that inside the inside of SSR. Sorry, sorry, sorry. Yep. So instead of that request auth, we can kinda drop that in here. And there's a nice comment from me that says returns the user's primary e-mail address. OK, so if you hit yeah, enter here, we can talk about it.
Essentially what's happening here is we're asking the user because your user could have 100 e-mail addresses attached to it essentially if they wanted to add a bunch of emails. So instead of having just a primary e-mail address, we return all the e-mail addresses that also have the option to find a primary e-mail address. This is the probably the most asked question that I've got when people start with SSR is like, hey, how do I get the like just I just want the primary e-mail. I don't want like all of them and I don't know how to figure this out.
So I have this piece of code lying around, and I have a blog post that's on the clerk's website about it as well. So so there's actually you could go directly to this too. Yeah, yeah, yeah. So, but the problem with that is, is let's say they signed in with their non primary e-mail, right? Then you're like, Oh no, those don't match like that. So this allows you to always 100% guarantee that you get the primary e-mail address.
So yeah, we can just run this piece of code and log it out and see what comes back. Well, we, we need to log it first. Let's. Clear that. You need to update your console dot log. Oh, sorry. Yep. Just let's just be e-mail now. Yeah. And then OK, so here we go. So this has all sorts of information that you may need, right? So in here is your e-mail address, which is Alex at cloning cat dot dev.
It has the verification where it was verified from all sorts of things that you may need to for whatever reason, some sort of business logic in the long on the other side, right? Maybe you decided you no longer want to support a Wharf from Google, so maybe you have to force them to re authenticate with a new provider or something like that.
Like all those things could be done in this SSR or you just need their e-mail address, right? Which is what I use it for. So yeah. So we could actually put this on screen. We could pass this as a prop. We could go to our database, for example, if Appright database has the e-mail address, you could go and make a request to Appright and be like, hey, I need all of the sales details for this e-mail and and you could do that right out of the gate in SSR, return that information on screen. And I would, I would totally do that right now, but we just upgraded to 10 and I'm afraid like literally. We don't want to paranoid that we may break our own upgrades to try and make this work.
Yeah, that is totally fine. But that's like the theory, right? Like even though we can't directly integrate with app, right, because we're just an off, well, we're more than an off provider, right? We're a user identity platform. So we can go and do these things even if we don't like aren't tightly integrated.
And, you know, now that you're working there and I'm working here, like we'll work on getting that done, however that may work. But yeah, like that's the whole point is that like, yeah, in some circumstances there just won't be an integration like planet scale. That's never going to be a JWT. So let's do something else.
It makes it really easy to to slot this in somewhere where maybe you have Firebase as your authentication provider and your database instead of having to worry about like, well, if I tear this out, like how am I going to access those details? Like, one, we have an integration with Firebase, so you can still get those. But two, like if you didn't want to use our direct integration, there's still other ways that you can you can do this so. Very cool.
Do you have components built for this version of the SSR where like we're getting that prop in and it's calling like an API for the rest of the data? So here's just stick with my brain for a minute. So you know how we had the signed in and the sign in and the signed out, all that stuff, Can we still use that in SSR now that we know we've authenticated? Yeah, if you wanted to, like I said before, your only issue is, is that like for signed in, for example, you run the risk of the client returning an error message because it's like, I don't know what I'm doing, like I don't understand the state I'm in right now.
But you can still like mount those sign in components. OK. So like the sign in and the user profile and the any of those kinds of things. So instead of redirecting to our hosted, you could redirect directly into the application, make one less network call, one less piece to the puzzle, which is another way that we we can kind of handle SSR and and and doing those kinds of things.
Cool. Yeah, that totally makes sense to me. Yeah. And So what? Go ahead. I was just going to say you got some more love coming your way from Hack. Big love all the way from Kenya. Appreciate it. Thanks for coming pretty late in Kenya. I would. Say, I was going to say it must be late in Kenya right now.
Yeah. Appreciate you coming out. Thanks. For hanging on for the night. Yeah. And what's cool about Next JS is that obviously they have the API, right? So you can make API calls and we can also protect your API calls. Oh, that's a great point. So you could do that both on their middleware as well, right? Right right.
So you have options so you can do it SSR you can do it on the AP is when we fix the edge middleware again after they broke it. Well, we had to do it on the edge middleware again, but it's 10:00 PM wow, thanks to. Thanks, I think it'd be later I guess. Not yeah, me too. Actually, I'm surprised it's not as late as I thought it would be.
You are just two hours ahead of my sister. Oh, there you go. Where's your sister? In the UK, yeah, she's in the UK, so it's 5 + 5 over there. Nice. Yeah, we're sitting at 3:00 PM our time right now, so only 7-7 hours away. Cool. Yeah, that's. Not bad, but yeah, so you can protect your API routes and you can also optionally protect your API routes.
So say you have an API that's like, I don't know, show a product, right? But maybe they're not logged in. So those are your options. You can either be logged in or you're not logged in. You can essentially have that as an option. So you can return data for when they're logged in and when they're not logged in as well.
So you have like the optional sort of API calls. Yeah, that's really cool, especially on the edge side of it. I think I'm sitting down with Tim Bennex on uniform and they do something very similar for the personalization. So that's really neat. That's that's a great point. I wouldn't even thought of that on the the login side. That's cool.
Instead of having the user be like, I have to type my name and my e-mail and everything else, you can just have the user send the message, whatever it will. And you can use your own user identity to like provide the session ID, the user, everything like that. So you can go and look in your logs and be like Oh yeah this happened at this time with this session ID like all that for the user as.
So if you're a big fan of Remix, like we have authentication for Remix and Redwood and Gatsby and just straight up the nil JavaScript, if you're real vanilla or you or there's a framework we don't support natively, you can use the vanilla JS to to handle it too. Yeah, I was thinking Angular is that a supported currently no that that's.
Fine, you could use the. You could use the vanilla JS to write scripts. Same with view as well. Views not supported right now and next is another one that's not supported right now. Those are on our list of things to add as the additional support, but we're aiming to provide the ones that people use the most, I suppose, the right answer. So things like React and Next JS, those things are like where we do the best, yeah.
That makes sense. So yeah, well, we probably can't dive too much deeper in that. We're coming up on time a little bit here. And is there anything else we completely missed? No, I think that's really it. Any pitches for clerk like sign up tomorrow we're doing an event or. Coming soon TM in October, talking about this in October we will be running a competition.
So if you're listening to this and it's October, there's a competition running right now where if you use our appearance prop that we showed off a little bit here and make a really nice design, you could win a cash prize. So that's, you know, first place I think is 500. Dollars. Try throw a link out somewhere, yeah? We will.
I'll send it to you because it's not ready yet. Like we don't have the comp up right now. We're working on the final pieces now. But yeah, I think the the cash prize is like a total of $1000 split between three people. And there's also a community version. So we're going to put every single design that you want that decides to be part of the community. Those will go on Twitter and whoever wins in the Twitter polls, we'll get an additional $200.00. So we're super excited.
I love it. That's super fun, Yeah. So it's basically going to run coincide with Hacktoberfest. It's going to be cool stuff, so. Perfect. And the app right's fully on board for Hacktoberfest, So you guys will see, you'll be inundated with information, I'll just put it that way. But all kinds of prizes, all kinds of fun coming down the pipe.
So it'll be super fun as well. Yeah, yeah, we're, we're excited for Hacktoberfest. I'm excited. I'm always excited every year. You know, what's funny is the last Oktoberfest, I think they ran into some issues where like people were putting in issues and things that they shouldn't and you know. Yeah, They were just doing like PRS for like adding white space and stuff to projects.
Yeah, yeah. And I, I heard they're, they figured out a way to like really track that and kind of cool figure that out. So we're looking forward to it. I'm kind of like nervously excited because of the issues. That. Yeah, me too. Yeah, we'll. See how it goes so. Oh, and also one more for for Oktoberfest.
So if you don't want to enter the competition, but maybe you live in a country other than an English speaking country, localization will be out by then. And we're offering, we're going to do a repo for translations. So if you don't want to do a bunch of code and all you want to do is like, hey, I just want to translate all this text, those will also count towards Oktoberfest.
That's very cool. I love that. Yeah, well, James, as always, really appreciate you coming on. I'm glad we could make this work. I know. Yeah, me too. Are rough in the fall so this works out well and we'll have to do some more training app right get get app rights logo on that log in there. Yeah, absolutely.
