<@U04UQ68083H> I am having issues setting up a loc...
# ory-copilot
s
@chilly-king-10285 I am having issues setting up a local environemnt for using ory with nextjs. I followed the tutorial and documentation and I didn’t get the expected result. I set up the project as explained in the docs but when I sign up in my local environment the identity does not show up in the ory console, so I guess its using some sort of sandbox or playground. Also to note I have set the NEXT_PUBLIC_ORY_SDK_URL env variable
c
A message from kapa.ai
I'm sorry to hear that you're having issues setting up a local environment for using Ory with Next.js. Let's try to troubleshoot this. Firstly, ensure that you have correctly set up your environment variables. The
NEXT_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:
Copy code
bash export NEXT_PUBLIC_ORY_SDK_URL=<http://localhost:4000>
For Windows, you can use:
Copy code
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:
Copy code
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:
Copy code
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.
s
@chilly-king-10285 when signing in to the ory cli it asks me for a usernae and password but I used google auth to sign into ory cloud, what do I do?
c
A message from kapa.ai
If you created your Ory account using a social sign-in provider like Google, you'll need to adjust your account configuration to use the Ory CLI. This is because accounts created with social sign-in providers don't use passwords, and to use your account with Ory CLI, your account must have a password. Here are the steps to create a password for an account created with a social sign-in provider: 1. Open the [Ory Console](https://console.ory.sh/) and sign in. 2. Go to your [account settings](https://console.ory.sh/settings). 3. Enter a new password in the Update Password field. 4. Click Save to finish. After setting a password, you should be able to use the Ory CLI with your existing account. You can find more information about this in the [Ory documentation](https://www.ory.sh/docs/guides/cli/cli-basics#accounts-with-social-sign-in).
s
@chilly-king-10285 how can I set an identity schema for all of my users, I want to set these two fields “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” ] } }, and in the meantime my schema looks like this { “$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”, “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 } }, “required”: [ “email” ], “additionalProperties”: false } } }
c
A message from kapa.ai
To add the
metadata_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:
Copy code
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:
Copy code
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).
s
@chilly-king-10285 how can I make the default be null?
c
A message from kapa.ai
To make the default value
null
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:
Copy code
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.
s
@chilly-king-10285 can I delete identity schemas I do not wish to use anymore?
c
A message from kapa.ai
Based on the provided knowledge sources, there is no direct method to delete an identity schema once it has been created. However, you can update an identity schema by creating a new revision of that schema. You can't update existing identity schemas by editing them directly. Here are the steps to update an identity schema: 1. Sign in to Ory Console and select [Identity Schema](https://console.ory.sh/projects/current/identity-schema). 2. Using the dropdown menu, select the schema you wish to update. 3. Check the Customize Identity Schema box to enable editing and make the necessary changes. 4. Enter a new name in the Identity Model Schema text box. 5. Click the Update button to save. It's recommended to manage identity schemas in version control. You can learn more about managing Ory Network configuration in git [here](http://ory.sh/docs/guides/gitops). If you want to stop using a particular schema, you can simply stop assigning it to new identities and update the existing identities to use a new schema. You can use the [patchIdentity API](https://www.ory.sh/docs/reference/api#tag/identity/operation/patchIdentity) to change the identity schema and traits directly. Please note that this information is based on the provided knowledge sources. For more detailed or specific information, you should refer to the official Ory documentation or contact Ory support.
s
@chilly-king-10285 will the schema apply to the pre set public_metadata object that each user has?
c
A message from kapa.ai
The
metadata_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).
s
@chilly-king-10285 I need to allow users to sign up with a specific sign up link, with that link they are automatically added some data in the public_metadata, how do I best do that? I am using nextjs
c
A message from kapa.ai
To achieve this, you can use a combination of Ory Kratos' self-service flows and your Next.js application logic. Here's a high-level overview of how you can do it: 1. Generate a unique sign-up link: In your Next.js application, generate a unique sign-up link for each user. This could be something like
<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:
Copy code
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).