Hello, just getting started with Ory Network now. ...
# _newcomer
w
Hello, just getting started with Ory Network now. I'm following this tutorial to build a basic SPA that logs in through Ory and returns back to a "home page" that is authenticated (https://www.ory.sh/docs/getting-started/integrate-auth/nextjsv) Next I want to make authenticated API calls to the server. How should I approach this? And in general, how would one store users in a database if the identity is being handled by a third party (Ory)? Cheers!
b
Next I want to make authenticated API calls to the server. How should I approach this? And in general, how would one store users in a database if the identity is being handled by a third party (Ory)?
@wooden-nightfall-55264, if you also have access and control over the server codebase, you could configure Ory Identity (Kratos) to send webhooks to the server after the registration. 1. This webhook will send the newly created identity (user) to the server 2. The server handles the request and create an internal user 3. The server creates a binding between the Ory identity and the user by assigning the
user.id
value to
identity.metadata_public.id
4. The server returns the mutated identity in the JSON response
Subsequent calls from the frontend to the backend (which contain the Ory cookie or token) allow the backend to verify the caller’s identity with the
Whoami
endpoint and retrieve the session that also contains the identity.
m
Could not have explained it better, thanks Edouard ❤️ (will see if I can add something to the docs here as well)
w
Awesome, this makes a lot of sense! Thank you so much! So for cookies those are set while logging in and sent alongside every request afterwards (as long as it's same-domain), right? Functionally, is there any difference between using cookies and using a token? I'm assuming that by tokens you mean JWT (https://www.ory.sh/docs/identities/session-to-jwt-cors)
m
With browser apps you have a cookie, for native / mobile you have a token: https://www.ory.sh/docs/identities/native-browser But you can also use a JWT