Authentication

SonicJs has a common token based authentication system allowing you login, obtain a valid token and supply that token to subsequent api requests.

Access Control

  1. To authorize via the API post to /v1/auth/login with the email and password in the body

    {
      "email": "[email protected]",
      "password": "password123"
    }
    
  2. The API will return a bearer token

    {
      "bearer": "eo0t9q52njemo83rm1qktr6kwjh8zu5o3vma1g6j"
    }
    
  3. Then add that bearer token to the Authorization header on future requests

    const url =
      'http://localhost:8788/v1/posts/c1d462a4-fd10-4bdb-bbf2-2b33a94f82aa'
    const data = {
      data: {
        title: 'Test Post Update',
      },
    }
    const requestOptions = {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer eo0t9q52njemo83rm1qktr6kwjh8zu5o3vma1g6j',
      },
      body: JSON.stringify(data),
    }
    fetch(url, requestOptions)
    
  4. You can now access the current user profile data at /v1/auth/user