Skip to content

Users API

Andrew Maclean edited this page Jun 29, 2024 · 3 revisions

This section describes the actions you can take on users with the Sunday Peak api.

Login a User

To login a user, you can pass an email and password to the login API endpoint. This will return a user object and an auth token that you can use in your session to complete further requests.

The login API doesn't require an auth token because it is a token-generating-request. Information about the user such as password hashes are hidden, since this isn't needed or usefull information.

Endpoint

https://api.sundaypeak.com/users/login

Content-Type: "application/json"
HTTP Method: POST

Request Body

{
    email: String,
    password: String,
    native: Boolean
}
Key Type Description
email String formatted with an @ separating an indentifier and a domain
password String Note: This request is secured with a TLS certificate so any data passed over https will be encrypted
native Boolean telling the backend whether this login is happening on a native app or a webapp

Response

{
    data: {
        user: User,
        token: String
    },
    status_code: Int,
    timestamp: Int
}
Key Type Description
user User
token String jwt token used to identify the session

Error Response

{
    error: {
        message: String,
        handled: Boolean,
        request_body: Object,
        code_error: String | Object
    },
    status_code: Int
}
Key Type Description
message String The text sent back describing what went wrong
handled Boolean Describes whether the error was described and caught before the final return or not
request_body RequestBody
code_error Object gives the internal description of the error if it was handled. Can give more context to the error
status_code Int The code of the returned error

Get a User From a Token

If a user is already logged in on a device, web or native, then there will be a token present. If a token is provided then the user doesn't need to re-authenticate. They can send the token to the server to get the user object.

This request returns all information in the user object relevant to Sunday Peak. Sensitive information such as password hashes aren't included.

Endpoint

https://api.sundaypeak.com/users/loggedIn

Content-Type: "application/json"

HTTP Method: GET

Bearer token: "Bearer <AuthToken>"

AuthToken is the jwt string returned when signing up or logging in to Sunday Peak.

Response

{
    data: {
        user: User
    },
    status_code: Int,
    timestamp: Int
}
Key Type Description
user User

Error Response

{
    error: {
        message: String,
        handled: Boolean,
        request_body: Object,
        code_error: String | Object
    },
    status_code: Int
}
Key Type Description
message String The text sent back describing what went wrong
handled Boolean Describes whether the error was described and caught before the final return or not
request_body RequestBody
code_error Object gives the iternal description of the error if it was handled. Can give more context to the error
status_code Int The code of the returned error

Clone this wiki locally