Тёмный
No video :(

GoLang & SvelteKit Custom Auth, it's Easier than you Think... (FULL EXAMPLE & SOURCE CODE PROVIDED) 

Ben Davis
Подписаться 17 тыс.
Просмотров 19 тыс.
50% 1

Should you roll your own auth? It's a hard question, and until very recently I was firmly against custom auth. However over time my opinions have changed, and today I am breaking down how to implement session auth in a GoLang backend, then use it with a SvelteKit frontend.
PROJECT SOURCE CODE: github.com/bmd...
🚀 DEPLOY YOUR BACKENDS 🚀
[Railway](railway.app/?r...)
My Socials
🐦 [twitter]( / benjamin41902 )
📷 [insta]( / bmdavis419 )
💾 [github](github.com/bmd...)
My Companies
📈 [insiderviz](www.insiderviz...)
📅 [BLOK](www.theblokapp...) (coming soon)
timestamps
0:00 intro
0:42 diagram breakdown
9:50 code breakdown
22:41 thoughts on custom auth
#sveltejs #webdevelopment #programming

Опубликовано:

 

15 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 95   
@RsZ789
@RsZ789 Год назад
Ben, thank you for all that you do for us. I hope you realize this RU-vid channel is great for your resume. It shows your ability to understand and teach concepts and shows your willingness to help others.
@Antonio-fo4fl
@Antonio-fo4fl Год назад
Some notes from the vid, 1. You can through a `use:enhance` action on form for progressive enhancement 2. In your sign in route action you should use the fetch provided by sveltekit. It is available on the event just like request, params and etc so you could do {request, fetch} in your default action to destructure event. 3. Akin to fetch you also have a setHeaders function that can be destructred from event as well
@bmdavis419
@bmdavis419 Год назад
Awesome info, thank you!
@sl554
@sl554 Год назад
Dude you are so right on time, the community needs stuff like this to move us all forward! So refreshing. Thank you for doing Sveltekit and Go. I'm all in on Sveltekit and learning Go to switch away from all TS/JS.
@shawnweddle3002
@shawnweddle3002 Год назад
Great video Ben. Glad I found your channel. I’ve been working on my personal portfolio lately with the hope of applying for (and getting) a web dev job soon. I tried using NextAuth (because of T3) and hated it. I really prefered writing my own custom auth. It gives me better understanding and better control of what I’m doing. I even started writing a separate auth backend in Rust that I hope to use in a project soon and this video has helped me understand how to connect everything better, even though you used Go and Sveltekit.
@bmdavis419
@bmdavis419 Год назад
Concepts hold true across languages, good luck!
@hope-ag
@hope-ag Год назад
Pure genius. I like how you handled the session between the frontend and 2 backends
@nabiih
@nabiih Год назад
Great video! Svelte + GO is a match made in heaven
@saper639
@saper639 7 месяцев назад
Thank you! You inspired me to use the Go Fiber+SvelteKit bundle. I'm following your ideas.
@ScriKidding-eg6vn
@ScriKidding-eg6vn Год назад
i just found this man finally SvelteKit and go content
@MrRe-sj2iv
@MrRe-sj2iv Год назад
If go with Go, I would choose PocketBase (still in developing stage) or stay with SvelteKit and Prisma for database ORM. Great content anyway. Thanks Ben
@naranyala_dev
@naranyala_dev Год назад
Golang and Svelte are perfect match, i love it
@blu5037
@blu5037 Год назад
Awesome video! Thank you and I really appreciate the time you put into this helping people understand these concepts easier.
@stephengruzin
@stephengruzin Год назад
Great video. Glad you're not importing the PageData type in the +page.svelte because the svelte extension automagically infers the page date variable.
@gmtborges
@gmtborges 5 месяцев назад
You can expose your golang backend as a binary and execute directly inside your SvelteKit server, that way you eliminate the extra HTTP roundtrip. Your app will run like the older CGI servers
@esiwk7
@esiwk7 Год назад
It is fantastic experience to replace from asp, mssql to sveltekit, golang, mongodb. So so so so faster than asp. How fast! Unbelievable!
@seanknowles9985
@seanknowles9985 Год назад
Kotlin multiplatform no tradeoffs, full cross platform, true native development, Jetpack Compose (similar to react) Multiplatform, coroutines, and solid ecosystem.
@KuroManX
@KuroManX Год назад
I am currently using Nuxt + Node, Sveltkit + Go seems to be a good stack as well, thinking of learning Go as a more powerful backend, and using node to small things.
@coffeeintocode
@coffeeintocode Год назад
Love this, great work. I really don’t like the Svelte backend though, feels unnecessary given you could do all of that work on Go that would be quicker & faster. Love the thought that went into the Auth though, eg it could work for a mobile app too 👌
@bmdavis419
@bmdavis419 Год назад
I’m gonna do a video soon about why doing this “double backend” pattern is used and the advantages it has. The key is that the sveltekit backend is really just the frontend cloud for our frontend which allows us to do things like prefetch data, server side redirects, ship less js due to using forms and doing the fetching on the server, and more. It’s less of a second backend, and more of giving our fe a cloud, which can talk the the go backend
@coffeeintocode
@coffeeintocode Год назад
@@bmdavis419 I’ll eagerly await that video then 😅 sorry mate, not sold on it. But equally, I kind of want to be wrong on this too 😂
@abdirahmann
@abdirahmann Год назад
@@bmdavis419 huuuuuuuuuuuuuuuuuuuh... idk, but please sell this idea to me cause i really don't want to be writing 2 backends, for these "allows us to do things like prefetch data, server side redirects", i think you need a proxy, cloudflare will happily do this for you 😄.
@bmdavis419
@bmdavis419 Год назад
The key is that it is not really a second backend, but more of a server for your cloud. I've heard it described as the "Frontend Cloud" which I think is a lot better. The point of it is to have a place for us to handle things serverside for our FE, while still having a full backend elsewhere. They don't do the same thing, and the FE Server is definitely not just a proxy. Gonna spend a lot of time to crystalize my thoughts on this one, vid probably after the Go+Svelte series is done in a week or two
@guitaripod
@guitaripod Год назад
Solid video, thanks for the source code.
@SAMEERSHAIKH-dw8rg
@SAMEERSHAIKH-dw8rg Год назад
Easiest way to create Json from formData is const a = Object.fromEntries(await request.formData())
@charlesbcraig
@charlesbcraig Год назад
Thoughts on GoTrue? Or did you discuss that in your JWT video. That’s what SupaBase uses underneath the hood
@behnamesmaili9916
@behnamesmaili9916 Год назад
Nice video. I love your stack. I am kind of doing this right now. But a sveltekit superforms is a thing I wanna recommend here.
@nicolaichristensen6531
@nicolaichristensen6531 Год назад
Nice video, also argon is preferred over bcrypt according to OWASP
@koomooboo
@koomooboo 4 месяца назад
@bmdavis419 What're the pros and cons if removing the Go Fiber immediate api layer? Use SvelteKit Server Actions or Server Side API to handle the db connection for auth and data storing?
@edrissndiaye
@edrissndiaye Год назад
🔥
@sergsergesrgergseg
@sergsergesrgergseg Год назад
thanks, ive spent months hitting my head, because everyone says you shouldn't implement your own authentication, but after doing it myself i didn't understand what i was missing.. all these people on all these forums are complete snobs and offer no alternative or helpful answers they just say no your stupid, do it this silly way with tons of extra overhead and over complexity edit: also why are u hosting 2 backends? u seem to be posting the svelte client data to the svelte api, then posting the data from the svelte api to the golang api..? why not just send it directly to go
@bmdavis419
@bmdavis419 Год назад
The idea is to have a sort of “front end cloud” obviously you don’t actually need it here, and the example is contrived it’s mostly to show how to do it with go
@skitsah9775
@skitsah9775 Год назад
Awesome video 🎉 Which app are you using for your annotations by the way?
@fire17102
@fire17102 Год назад
Hi Ben love your videos! Can you perhaps steelman the case for using redis as your primary db? Thanks a lot and all the best!
@bmdavis419
@bmdavis419 Год назад
That is a great idea, I have added it to the board!
@fire17102
@fire17102 Год назад
@@bmdavis419 im happy to hear haha :) I use redis alot, it has great pub/sub features, you can sync between services in multiple languages in realtime. Great especially for data driven systems and applications. Though I'd use zmq if I prepare for really big data transfers
@keyhanalizadeh1991
@keyhanalizadeh1991 Год назад
Please a full course for a blog app with go , fiber and mongo db
@bmdavis419
@bmdavis419 Год назад
Might do that with a sveltekit fe and a relational db (I’ve been souring on mongo lately)
@keyhanalizadeh1991
@keyhanalizadeh1991 Год назад
@@bmdavis419 very niceeee The rest api just can be good Thats going to be a good course Auth, input validation and media upload 👀 We are waiting
@chrisevans2241
@chrisevans2241 Год назад
use sequence diagram to explain flow of a request
@tirumalraot
@tirumalraot 8 месяцев назад
My Stack Golang + Sveltekit + TailwindCSS + Keycloak + Postgres + Redis
@kokizzu
@kokizzu Год назад
2 of my favorite language! XD
@kokizzu
@kokizzu Год назад
but i prefer svelte over sveltekit
@AlexBezhan
@AlexBezhan Год назад
HTML allows me to do server-side rendering. I don't need meta-framework for that:)
@bmdavis419
@bmdavis419 Год назад
XD
@ESArnau
@ESArnau Год назад
Question, wouldn't be safer to hash the password before sending it from sveltekit's "backend" to the go backend?
@bmdavis419
@bmdavis419 Год назад
Since we don’t save it it’s fine
@anselminos5238
@anselminos5238 Год назад
there could be some performance implications if it would be hashed with a js implementation of a hashing function, but afaik the node crypto package has native implementations which in contary could be faster than go.
@ashimov1970
@ashimov1970 Год назад
is SvelteKit BE in fact a BFF (the backend for the SvelteKit FE)?
@bmdavis419
@bmdavis419 Год назад
Yep
@gabefgonc
@gabefgonc Год назад
hey ben! can you do a video about clean architecture in go?
@oussamasethoum1665
@oussamasethoum1665 Год назад
super nice orm is ent
@stephengruzin
@stephengruzin Год назад
or gorm
@oussamasethoum1665
@oussamasethoum1665 Год назад
@@stephengruzin ent is better
@coffeeintocode
@coffeeintocode Год назад
Thanks for sharing this! Looks very good, will play with this tonight
@oussamasethoum1665
@oussamasethoum1665 Год назад
@@coffeeintocode you're welcome sir.
@bmdavis419
@bmdavis419 Год назад
Planning a video where I talk about go’s database situation, will add ent to the list
@AlexBezhan
@AlexBezhan Год назад
Why use Redis when you can use SQLite which will be even faster?
@bmdavis419
@bmdavis419 Год назад
I've never heard that before, I'll look into it...
@neociber24
@neociber24 Год назад
Redis is more versatille than use SQLite as a cache
@grizzle8911
@grizzle8911 Год назад
Couldn't you do all the cookie stuff in go and avoid having a second backend that seems to be only acting as a http client ?
@bmdavis419
@bmdavis419 Год назад
Yep this was contrived for the sake of an example
@ashimov1970
@ashimov1970 Год назад
Ben, based on your XP, what would you recommend as a Golang BE framework? Fiber or what?
@bmdavis419
@bmdavis419 Год назад
I like fiber personally, all of them are good and while you technically don’t need one, I would use one as they will are your life a lot easier
@elia5562
@elia5562 Год назад
Great video! but why await JSON.stringify()
@cb73
@cb73 Год назад
I'm pretty sure (though only now am I questioning it) that sending a Bearer token is only need for making authenticated REQUESTS. They are not required for the http RESPONSE. You could have just sent it as part of the JSON response. Then no need to strip the "Bearer" part of it.
@bmdavis419
@bmdavis419 Год назад
Oh yea for sure, it’s completely irrelevant if it’s there or not I just like it by convention
@user-oj4ed9ig5o
@user-oj4ed9ig5o Год назад
what is the name of the application where you are drawing stuff to explain us. I am in need of this, to plan my project and make system designs
@bmdavis419
@bmdavis419 Год назад
excalidraw
@ESArnau
@ESArnau Год назад
Why do u add Bearer to the session id string?
@bmdavis419
@bmdavis419 Год назад
Because that’s what people do, honestly idk it’s just a convention
@ESArnau
@ESArnau Год назад
@@bmdavis419 cool
@tinkerbaj9852
@tinkerbaj9852 Год назад
How to include auth2 in this story?
@evangelossyrmos9576
@evangelossyrmos9576 Год назад
Why don't you use an Open Source authentication and user management tool (such as Keycloak, SuperTokens). They do the same think sort of and are backed by the open source community and great developers. An increasing number of small tech companies that want a single IAM (Identity and Access Management) platform rely on open source software that can be hosted on their VMs and use their existing Databases... I worked in a startup that our IAM was built on Keycloak and all services afterwards were created in different realms in order to separate concerns. However, in my PoC that I built I had some issues with the JS Keycloak wrapper, forcing me to built my PaaS with SuperTokens. Great video nevertheless!
@_timestamp
@_timestamp Год назад
16:25 const body = JSON.stringify(Object.fromEntries(formData)); 19:45 set compilerOptions.noImplicitAny or compilerOptions.strict to false in tsconfig.json; or write it as "...async (event: any) => ..."
@leo_dipp
@leo_dipp Год назад
Ben, what's the name of that software that you use to draw diagrams?
@multivitamin7
@multivitamin7 Год назад
Excalidraw
@ruchi__
@ruchi__ Год назад
Provider is always better because you have someone to blame if something goes wrong.
@bmdavis419
@bmdavis419 Год назад
That was always my thinking lol
@realhuna
@realhuna 6 месяцев назад
7:25 hey what is this board app?
@bmdavis419
@bmdavis419 6 месяцев назад
excalidraw
@realdebil.
@realdebil. Год назад
What's the point of creating another backend in Go if you already have a backend from Sveltekit? It's not possible to connect to databases from Sveltekit?
@ingloriouspancake7529
@ingloriouspancake7529 Год назад
I feel like auth0 is gone down hill
@yjawhar
@yjawhar Год назад
I still don't understand why are you using Sveltekit instead of doing everything with Go.
@abdellahcodes
@abdellahcodes 11 месяцев назад
Sveltekit is great, but the auth story is sorely lacking :(
@bmdavis419
@bmdavis419 11 месяцев назад
Currently checking out Lucia for auth, will make a video once I spend more time with it!
@abdellahcodes
@abdellahcodes 11 месяцев назад
@@bmdavis419 I'm using it dor the past week and it's great The best way to own your auth
@mohabedr5030
@mohabedr5030 2 месяца назад
too much talk
Далее
Go Fiber + SQLx
11:09
Просмотров 11 тыс.
Svelte 5 is Bigger Than You Think
9:35
Просмотров 19 тыс.
How and Why I Rebuilt my SAAS App
13:24
Просмотров 20 тыс.
I want to use Go, but I'm not going to.
18:31
Просмотров 33 тыс.
i didn't know these Svelte tips
18:56
Просмотров 4,7 тыс.
Svelte 5's Secret Weapon: Classes + Context
18:14
Просмотров 16 тыс.
THIS is the BEST Way to Write HTTP Services in Golang
13:53
I forced EVERYONE to use Linux
22:59
Просмотров 346 тыс.
Protect SvelteKit Routes with Hooks
21:10
Просмотров 55 тыс.
The Truth about Rust/WebAssembly Performance
29:47
Просмотров 177 тыс.