Custom auth solidstart by prisma
Can anyone help me make my authorization on solidstart? I have orm prisma. I created a user table, what else do I need? 1) how to authorize a user, I have an endpoint trpc. 2) when entering the site, I should receive information about the user; if the error code is 401, then the user is redirected to the logIn page
53 Replies
are you familiar with password hashing? That's a very important aspect to rolling your own auth...
I'm most interested in storing cookies, I haven't seen any working plugins
I don't know all the ins and outs of auth, but I used lucia for my last project and really liked it bc it doesn't try to be in your way too much. It can easily be used in combination with orm and has documentation on how to set that up.
It gives u the feeling like u are rolling out your own auth, while the library (and their rly good documentation) guides you through it. So I would even recommend it as an educational thing if you eventually wanna roll it out all by yourself.
I used it w astro back then, but they have a section for solidstart too: https://lucia-auth.com/getting-started/solidstart
Lucia
Getting started in SolidStart
Lucia is an open source auth library that abstracts away the complexity of handling sessions.
@sh1man what was out of date?
@solid-primitives/storage
ah lol
I'm also interested in authorization and storage of tokens jwt. Because I don’t always use solidstart
Therefore, in such cases, I don’t know how to use cookies for storage and which plugin can help me with this
Use Jose to create + sign a jwt and call a function in your api handlers that verifies the jwt
how to display ui after verification?
as they usually do
Same way as with sessions, make a normal query to get the current user
and if I use an eternal token on the server, what should I do in this case, how to store it in cookies?
Ideally the frontend isn’t even aware of the cookie (as happens with Lucia), just request the current user and if there is none then go to a login page
there is an example
I don’t know how to do this correctly in solid
You’re using trpc no? Do a trpc query for the current user and if you get null then navigate to login with your router
yes, i use trpc
In the main file?
app.tsx
If you’ve got access to trpc and the router there yeah
It seems to me that the ui will load faster than the request will be executed
Though I doubt you want all of your routes to require auth so consider doing it in a lower down layout instead
Use Show to not render the children until you get a response
but it hits the login page
Then do this - put your auth-requiring routes in a dedicated group and do the auth check in that group’s layout
Login can exist outside that group and not require auth
how to do it
I haven't seen this
There’s probably solid start examples that show how do to groups and layouts
do you mean use layouts
?
Yea that’s what I said
Then in this layout use trpc request
Yes, that request is the auth check
Thanks I got it
Notice that the ‘auth’ part of this problem is just getting the cookie/jwt to the client
I'm wondering how to safely store data in cookies
I use very often third-party authorization backend in python
Use Lucia or use start’s header/session helpers + research how to secure cookies
but the authorization backend is not on the solidstart side
db only python backend
Is the browser expected to query the Python server directly?
Or is that done through trpc
only api get json data
What
backend server python only for receiving data via API
authorization is also on this server, in return I receive a permanent authorization token
Then write the token to a cookie in trpc and then extract the token from the cookie + manually pass it to the requests to Python
Then the browser will have the token in a cookie that will the be forwarded through trpc to the Python server
Does trpc have cookies to store them there?
Well no it’s just an api handler, the incoming request from the browser has cookies
how to write cookies then?
With start/h3’s header/session helpers
That will get the cookie to/from the browser
How the token gets to the Python server is up to how the Python server works
I need examples about this. I've never seen this
They’re in the start docs, what you need may be more research on your tools
https://start.solidjs.com/advanced/session
Okay, what if I use Astro + solid.js
What about it?
You’ll need to handle headers/cookies/request handling in the way Astro does it
okay, thank you
I don't understand how to redirect a user in trpc
not sure u can redirect in trpc directly
How to redirect using TRPC? - Theo's Typesafe Cult
I am generating stripe checkout url from trpc endpoint and want to redirect user to that page.
Here is what I am doing right now
```export const purchaseRouter = createTRPCRouter({
getUrl: publicProcedure
.input(z.object({ text: z.string() }))
.query(async ({ input, ctx }) => {
const host = ctx.req.headers.host;
if (!host) ...
any reason why you are using trpc instead of solid-start's server-functions?
redirect in the client using
useNavigate
from the routerno, the reason is I just don’t understand how to use solidstart
Okey
Can someone show me an example of getting a user profile?