some-painting-28549
04/24/2024, 11:55 AMchilly-king-10285
04/24/2024, 11:55 AMchilly-king-10285
04/24/2024, 11:55 AMNEXT_PUBLIC_ORY_SDK_URL
should be set to your local Ory instance if you're running it locally. For Unix systems, you can set it up like this: bash export NEXT_PUBLIC_ORY_SDK_URL=<http://localhost:4000>
For Windows, you can use: powershell $Env:NEXT_PUBLIC_ORY_SDK_URL = "<http://localhost:4000>"
You can find more details about setting environment variables with Next.js [here](https://nextjs.org/docs/basic-features/environment-variables). Next, make sure you have started your application locally. You can do this by running: bash npm run dev -- --port 3000
This will start your app on port 3000. In a new terminal window, you should run Ory Tunnel (part of the Ory CLI) to connect the application to your Ory Network project: bash ory tunnel <http://localhost:3000> --project {project-slug} --dev
To get your project slug, go to 'Access & APIs' in Ory Console at https://console.ory.sh/. Finally, in your browser, go to http://localhost:3000 to access the application. From there, you should be able to register and sign-in using the Ory Elements-powered pages. If you're still having issues, it might be helpful to check the route you've set up in [...paths].js
at pages/api/.ory/
. This route connects your Next.js app with Ory's APIs and ensures that all cookies and credentials are set up. Without it, your Next.js application won't be able to talk to Ory's APIs. You can find more details about this [here](https://www.ory.sh/docs/guides/cli/proxy-and-tunnel). If you're still having issues after checking these steps, please provide more details about the issues you're experiencing so we can better assist you.some-painting-28549
04/24/2024, 12:07 PMchilly-king-10285
04/24/2024, 12:08 PMchilly-king-10285
04/24/2024, 12:08 PMsome-painting-28549
04/24/2024, 12:30 PMchilly-king-10285
04/24/2024, 12:30 PMchilly-king-10285
04/24/2024, 12:31 PMmetadata_public
field to your identity schema, you can simply add it to the properties
object under traits
. Here's how your updated schema would look: json { "$id": "<https://schemas.ory.sh/presets/kratos/identity.email.schema.json>", "title": "Person", "type": "object", "properties": { "traits": { "type": "object", "properties": { "email": { "type": "string", "format": "email", "title": "E-Mail", "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "password": { "identifier": true }, "webauthn": { "identifier": true }, "totp": { "account_name": true }, "code": { "identifier": true, "via": "email" } }, "recovery": { "via": "email" }, "verification": { "via": "email" } }, "maxLength": 320 }, "metadata_public": { "org_id": { "type": "string", "title": "The organisation the user belongs to", "default": "unset" }, "role": { "type": "string", "title": "The user role they have been set to", "default": "user", "enum": [ "user", "org-admin", "superadmin" ] } } }, "required": [ "email" ], "additionalProperties": false } } }
After updating your schema, you can use the Ory CLI to update your project's configuration. Here's an example of how to do this: bash # Encode your schema to Base64 and export it to a variable. schema=$(cat {path-to-json-with-identity-schema} | base64) # Update your project's configuration. ory patch identity-config {your-project-id} \ --replace '/identity/default_schema_id="{unique-schema-id}"' \ --replace '/identity/schemas=[{"id":"{unique-schema-id}","url":"base64://'$schema'"}]'
Replace {path-to-json-with-identity-schema}
with the path to your updated JSON schema file, {your-project-id}
with your Ory project ID, and {unique-schema-id}
with a unique ID for your schema. You can find more information about managing identity schemas in the [Ory documentation](https://www.ory.sh/docs/identities/model/manage-identity-schema).some-painting-28549
04/24/2024, 12:32 PMchilly-king-10285
04/24/2024, 12:32 PMchilly-king-10285
04/24/2024, 12:32 PMnull
for the org_id
and role
fields in your identity schema, you can simply set "default": null
in the respective field definitions. Here's how your updated schema would look: json { "metadata_public": { "org_id": { "type": "string", "title": "The organisation the user belongs to", "default": null }, "role": { "type": "string", "title": "The user role they have been set to", "default": null, "enum": [ "user", "org-admin", "superadmin" ] } } }
Please note that setting a default value to null
means that if no value is provided for these fields, they will be set to null
. If you want these fields to be required (i.e., a value must be provided), you should add them to the required
array in your schema.some-painting-28549
04/24/2024, 12:33 PMchilly-king-10285
04/24/2024, 12:33 PMchilly-king-10285
04/24/2024, 12:34 PMsome-painting-28549
04/24/2024, 12:37 PMchilly-king-10285
04/24/2024, 12:37 PMchilly-king-10285
04/24/2024, 12:37 PMmetadata_public
field is not validated using the identity's JSON schema. It's a system-defined attribute that can't be updated or modified by the identity owner. The only way to update the metadata is to use the /admin/identities
APIs. The identity schema primarily defines the data model of your identities and controls business logic. It specifies the types of data the system can store for users, such as their names, email addresses, phone numbers, and birthdays. It also allows you to define additional fields that can be added to user profiles, such as job titles, company names, or locales. So, while you can define the structure of metadata_public
in your identity schema, it won't be validated against the schema. You must ensure that the metadata you store is valid according to your schema and you must keep the schema up to date to accommodate changes in the data. You can find more information about managing identity metadata in the [Ory documentation](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).some-painting-28549
04/24/2024, 12:39 PMchilly-king-10285
04/24/2024, 12:40 PMchilly-king-10285
04/24/2024, 12:40 PM<https://your-app.com/signup?invite=unique-code>
. The unique-code
could be any string that uniquely identifies the user or the data you want to add to public_metadata
. 2. Handle the sign-up link in your Next.js app: In your Next.js app, handle the /signup
route. Extract the invite
parameter from the URL. You can use the useRouter
hook from next/router
to do this. 3. Start the registration flow with Ory Kratos: When the user visits the sign-up link, start the registration flow with Ory Kratos. You can do this by making a request to the /self-service/registration/api
endpoint. This will give you a flow_id
. 4. Complete the registration flow: Present the registration form to the user. When the user submits the form, make a request to the /self-service/registration/api
endpoint again, this time including the flow_id
and the form data. Also include the invite
parameter in the traits
field. 5. Update the user's public_metadata
after registration: After the user has successfully registered, you can update the public_metadata
field of the user's identity. You can do this by making a request to the /identities/{id}
endpoint of the Ory Kratos Admin API, where {id}
is the ID of the user. In the request body, include the public_metadata
field with the data you want to add. Here's an example of how the request body could look: json { "schema_id": "default", "traits": { // The rest of the user's traits... }, "public_metadata": { // The data you want to add... } }
Please note that this is a high-level overview and the exact implementation may vary depending on your application's requirements and configuration. You can find more information about self-service flows and the Admin API in the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-registration).