hundreds-psychiatrist-38730
08/18/2025, 6:32 PM{ session } = useSession()
or session = getServerSession()
I can ofc also read on https://www.ory.sh/docs/kratos/manage-identities/best-practices#keep-your-data-lean that I should NOT store business logic in the Kratos DB.
What is the "best" way or even recommended way to get my additional info out?
in a former code base I have i made my own useSession()
/ getServerSession()
functions that wraps Kratos but then also does a request to my own backend.
It would give me session
& profile
consts where I can access the data, i'm not sure if i like that 😞
I would kinda love to use Ory Actions
or Webhooks in the on-prem solution.
But currently the Request Authentication
in that is limited to either basic api key auth or basic_auth
neither are good 😞bland-eye-99092
08/18/2025, 8:39 PMIt would give methat sounds like a reasonable solution, what don't you like about it? You could utilize something like Promise.all in a react query to only return once both are fetched.&session
consts where I can access the data, i'm not sure if i like thatprofile
I would kinda love to useor Webhooks in the on-prem solution.Ory Actions
But currently thecould you expand on this a bit? In what context do you want to use the actions?in that is limited to either basic api key auth orRequest Authentication
neither are good 😞basic_auth
hundreds-psychiatrist-38730
08/18/2025, 9:21 PM@ory/nextjs
or even @ory/elements/element-react
For the ory actions.
I don't feel like a single Api key for Auth between my frontend (server or client side) to my backend service is super secure.
Same with basic Auth.
I do want to leverage kratos and keto in my backend, so why shouldn't I be able to use that for Auth when an action is triggered.bland-eye-99092
08/18/2025, 9:46 PMI feel like it would be nicer to have them as one, so simply have it on an interface.I agree, however, think of it this way: Kratos is not a database. What happens if a business requirement comes along, that requires changing the datatype of one of the fields to an array? In a database, that's a fairly trivial operation, change the schema, run some migrations, and you're done. In kratos, this requires more work, because you need to update the identity schema, update existing identities, etc. Also there is no schema for more complex data, nor relationships between different datafields. I'd always prefer the flexibility, over the initial convinience.
I don't feel like a single Api key for Auth between my frontend (server or client side) to my backend service is super secure.Kratos handles end-user identities, not service-to-service auth. When Kratos' webhooks fire, that's server side code, not client side. If you self-host Kratos, you might even set it up in a way, that the traffic between Kratos and your webhook target never leaves the internal network. Or on your webhook target, you whitelist the IP address that Kratos is making requests from. You can also always rotate those keys, if you control both sides. There are plenty of ways to make this system even more secure, even though it really isn't necessary, as long as you keep the API key confidential. Does this answer your question?
hundreds-psychiatrist-38730
08/19/2025, 2:50 PMI agree, however, think of it this way: Kratos is not a database. What happens if a business requirement comes along, that requires changing the datatype of one of the fields to an array? In a database, that's a fairly trivial operation, change the schema, run some migrations, and you're done. In kratos, this requires more work, because you need to update the identity schema, update existing identities, etc. Also there is no schema for more complex data, nor relationships between different datafields. I'd always prefer the flexibility, over the initial convinience.I fully agree on this 🙂 makes total sense also from a sys-admin POV which is my field.
Kratos handles end-user identities, not service-to-service auth. When Kratos' webhooks fire, that's server side code, not client side. If you self-host Kratos, you might even set it up in a way, that the traffic between Kratos and your webhook target never leaves the internal network. Or on your webhook target, you whitelist the IP address that Kratos is making requests from. You can also always rotate those keys, if you control both sides. There are plenty of ways to make this system even more secure, even though it really isn't necessary, as long as you keep the API key confidential. Does this answer your question?Ofc everything will be on the inner network, nothing public for that since it's backend. so just to write it in stone i guess (how i best understand stuff). "best" to use API Key between kratos & my backend service. have it made to change that key on-the-fly, i know kratos hot reload based on config changes, so should my backend and then ofc have that key somewhere else for security ofc. So, how should I secure my backend and basically authenticate my users into it? The kratos user id that is created on registration is "copied" over to my own DB. But obviously i don't want any user to just be able to access other users data 😛 my backend is made in golang. This is ofc when thinking about using Actions/Webhooks. If not using that, then I guess i would need to take the session cookie and send that in my server side requests from NextJS and simply do the
validateSession()
from https://www.ory.sh/docs/kratos/self-hosted/go (gin middleware).
I apologize for the long message @bland-eye-99092 🙂 but i do appreciate the help.hundreds-psychiatrist-38730
08/19/2025, 3:00 PMconst { session, profile } = useSessionContextStore(useShallow((s) => ({ session: s.session, profile: s.profile })))
where I use Zustand state management to put in the Session
from Kratos and also my own profile
data.
that basically means, wrap the SDK client and not use @ory/nextjs
or @ory/elements/element-react
but basically just do what @ory/nextjs
is doing and use the @ory/typescript-fetch
Since the SDK client isn't exported in @ory/nextjs
🙂bland-eye-99092
08/19/2025, 4:05 PMBut obviously i don't want any user to just be able to access other users data 😛how would they?
And what about what about the 2 variabless?Sounds good to me, what's the issue? @ory/nextjs and @ory/elements-react are just packages, that contain helper functions.
hundreds-psychiatrist-38730
08/19/2025, 5:03 PMhow would they?I don't know, i'm not team red 😛 i'm team blue. I just don't want to have a fully open rest api, even on the inside of my network. that just screams in my head. And if the key gets leaked ? even worse.
bland-eye-99092
08/19/2025, 5:30 PMdon't want to have a fully open rest apiit's not, you're requiring an api key to talk to it, no? If the key is leaked, you rotate it.
hundreds-psychiatrist-38730
08/19/2025, 5:31 PMsteep-lamp-91158
hundreds-psychiatrist-38730
08/20/2025, 1:15 PMsteep-lamp-91158
hundreds-psychiatrist-38730
08/20/2025, 1:50 PMhundreds-psychiatrist-38730
08/20/2025, 1:51 PMsteep-lamp-91158