---
tags:
  - name: Passwordless
    description: All the routes related to the authentication with loginToken

paths:
  "/passwordless/login":
    get:
      tags:
        - Passwordless
      summary: Login a user with one time password
      parameters:
        - in: query
          name: loginToken
          required: true
          description: Login token from the email
          schema:
            type: string
      responses:
        200:
          description: Connection
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Passwordless-User"
        400:
          description: Bad Request
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Error"
        default:
          description: Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

  "/passwordless/send-link":
    post:
      tags:
        - Passwordless
      summary: Send an email to user with login link
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Passwordless-SendLinkRequest"
      responses:
        200:
          description: Returns email and boolean to confirm email was sent
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Passwordless-EmailSent"
        400:
          description: Bad Request
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Error"
        default:
          description: Error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"

components:
  schemas:
    Passwordless-EmailSent:
      type: object
      properties:
        email:
          type: string
        username:
          type: string
          nullable: true
        sent:
          type: boolean
          example: true

    Passwordless-User:
      allOf:
        - $ref: "#/components/schemas/Users-Permissions-UserRegistration"
        - type: object
          properties:
            context:
              type: object

    Passwordless-SendLinkRequest:
      type: object
      properties:
        email:
          description: the user email
          required: true
          example: foo@bar.com
          type: string
        username:
          example: foo
          description: username for new user
          type: string
        context:
          description: context of authentification
          type: object
          example:
            currentUrl: localhost
