User schema
Users in Nick have a set of properties defined by a default set of fields such as fullname, email, and so on. These properties define the site user’s profile and the user itself via the UI.
Get the schema for the user profile
To get the current schema for the user profile, make a request to the /@userschema endpoint.
GET /@userschema HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk
Or use the client directly:
import { Client } from '@robgietema/nick';
const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });
const { data } = await cli.getUserSchema({
token: login.data.token,
});
The server will respond with the user profile schema.
HTTP/1.1 200 OK
Content-Type: application/json
{
"fieldsets": [
{
"fields": [
"fullname",
"email"
],
"id": "default",
"title": "Default"
}
],
"properties": {
"email": {
"description": "We will use this address if you need to recover your password",
"title": "Email",
"type": "string",
"widget": "email"
},
"fullname": {
"description": "Enter full name, for example, John Smith.",
"title": "Full Name",
"type": "string"
}
},
"required": [
"email"
]
}
The user schema uses the same serialization as the type’s JSON schema.
Get the registration form
In Nick you can configure each of the fields of the user schema to be available in only one of either the user profile form or registration form, or in both of them.
To get the user schema available for the user registration form, make a request to the @userschema/registration endpoint.
GET /@userschema/registration HTTP/1.1
Accept: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZG1pbiIsImZ1bGxuYW1lIjoiQWRtaW4iLCJpYXQiOjE2NDkzMTI0NDl9.RS1Ny_r0v7vIylFfK6q0JVJrkiDuTOh9iG9IL8xbzAk
Or use the client directly:
import { Client } from '@robgietema/nick';
const cli = Client.initialize({ apiPath: 'http://localhost:8080' });
const login = await cli.login({ username: 'admin', password: 'admin' });
const { data } = await cli.getRegistrationSchema({
token: login.data.token,
});
The server will respond with the user schema for registration.
HTTP/1.1 200 OK
Content-Type: application/json
{
"fieldsets": [
{
"fields": [
"fullname",
"email",
"username",
"password",
"password_ctl",
"mail_me"
],
"id": "default",
"title": "Default"
}
],
"properties": {
"email": {
"description": "We will use this address if you need to recover your password",
"title": "Email",
"type": "string",
"widget": "email"
},
"fullname": {
"description": "Enter full name, for example, John Smith.",
"title": "Full Name",
"type": "string"
},
"mail_me": {
"default": false,
"description": "",
"title": "Send a confirmation mail with a link to set the password",
"type": "boolean"
},
"password": {
"description": "Enter your new password.",
"title": "Password",
"type": "string",
"widget": "password"
},
"password_ctl": {
"description": "Re-enter the password. Make sure the passwords are identical.",
"title": "Confirm password",
"type": "string",
"widget": "password"
},
"username": {
"description": "Enter a user name, usually something like 'jsmith'. No spaces or special characters. Usernames and passwords are case sensitive, make sure the caps lock key is not enabled. This is the name used to log in.",
"title": "Username",
"type": "string"
}
},
"required": [
"email",
"username",
"password",
"password_ctl"
]
}
The user schema uses the same serialization as the type’s JSON schema.