Hierarchy

  • AuthClient

Implements

Constructors

Properties

httpService: IHttpService
keyStorage: IKeyStorage
projectId: string
sessionService: SessionService
tokens: Tokens

Accessors

Methods

  • This method is used in combination with the passwordless method and is used to confim the authentication link

      let params = new URLSearchParams(window.location.search)

    auth.confirmPasswordless(
    id: params.get("id"),
    token: params.get("token"),
    )

    Parameters

    • id: string
    • token: string
    • Optional config: Partial<Request>

    Returns Promise<void>

  • Get a new AccessToken for a given session, this method will force a new tokem even if the current token is still valid

    Parameters

    • Optional sessionId: string

      when sessionId is undefined, the currently active session will be used

    Returns Promise<string>

  • Parameters

    • fn: ((session: Session) => Promise<string>)
        • (session: Session): Promise<string>
        • Parameters

          Returns Promise<string>

    • Optional sessionId: string

    Returns Promise<string>

  • Get an AccessToken for a given session, getting a new token when the current token expires

    Parameters

    • Optional sessionId: string

      when sessionId is undefined, the currently active session will be used

    Returns Promise<string>

  • handle the OAuth callback and sign in the user if the code and csrf_token are valid

     let params = new URLSearchParams(window.location.search)
    auth.oAuthConfirm(params.get("state"), params.get("code"))

    Parameters

    • csrf_token: string
    • code: string
    • Optional config: Partial<Request>

    Returns Promise<[null | User, string]>

  • Create new session using an authentication link, if the user does not exits, a new user will be created

    Parameters

    • email: string
    • Optional config: Partial<Request>

    Returns Promise<{
        id: string;
        session: string;
    }>

  • Request to reset the current user password, if the user exists a rest email will be send to the given email address, no email will be send if the user does not exits, however the success screen will be shown in both cases

    Parameters

    • email: string

      the user email address

    • Optional config: Partial<Request>

    Returns Promise<void>

  • This method is use in combination with the resetPassword method, the generated link to reset your password contains a token id and the token value that will be used to reset the password

      let params = new URLSearchParams(window.location.search)

    auth.setResetPassword({
    id: params.get("id"),
    token: params.get("token"),
    password1: 'new-password',
    password2: 'new-password',
    })

    Parameters

    Returns Promise<void>

  • Create a new session with Email and Password

     <form id="signIn">
    <section>
    <label>Email</label>
    <input name="email" type="email" />
    </section>

    <section>
    <label>Password</label>
    <input name="password" type="password" />
    </section>

    <button>Sign In</button>
    </form>

    <script>
    let auth = Auth.create({ /\* config */})
    let signIn = document.querySelector("#signIn")

    signIn.addEventListener("submit", async (event) => {
    event.preventDefault()

    let formData = new FormData(event.target)
    let user = await auth.signIn(
    formData.get("email"),
    formData.get("password"),
    )
    })
    </script>

    Returns

    the user

    Parameters

    • email: string

      The user email address

    • password: string

      The user password *

    • Optional config: Partial<Request>

    Returns Promise<User>

  • Sign out a user from the current session

    Parameters

    • Optional sessionId: string

      when sessionId is undefined, the currently active session will be used

    • Optional config: Partial<Request>

    Returns Promise<unknown>

  • Sign out a user from all sessions

    Parameters

    • Optional sessionId: string

      when sessionId is undefined, the currently active session will be used

    • Optional config: Partial<Request>

    Returns Promise<unknown>

  • Create a new session with Email and Password and create the user if not exists

     <form id="signUp">
    <section>
    <label>Email</label>
    <input name="email" type="email" />
    </section>

    <section>
    <label>Password</label>
    <input name="password" type="password" />
    </section>

    <button>Sign Up</button>
    </form>

    <script>
    let auth = Auth.create({ /\* config */})
    let signUp = document.querySelector("#signUp")

    signUp.addEventListener("submit", async (event) => {
    event.preventDefault()

    let formData = new FormData(event.target)
    let user = await auth.signUp(
    formData.get("email"),
    formData.get("password"),
    )
    })
    </script>

    Parameters

    • email: string

      The user email address

    • password: string

      The user password

    • Optional config: Partial<Request>

    Returns Promise<User>

  • Verify a users email address

    When the VerifyEmail flag is set, an email will be send to the user containing a link to verify the email.

    ```js let params = new URLSearchParams(window.location.search)

    auth.verifyEmail( id: params.get("id"), token: params.get("token"), )

    Parameters

    • id: string
    • token: string
    • Optional config: Partial<Request>

    Returns Promise<void>

  • This method is used in combination witht the passwordless method, it polls the server for update and resolves the promise once the authentication link has been confirmed

      let { id, session } = await auth.passwordless("email@vulpo.dev")
    let user = await auth.verifyPasswordless(id, session)

    Parameters

    • id: string
    • session: string
    • Optional config: Partial<Request>

    Returns Promise<null | User>

  • This method is used in combination with the setPassword method and is used to valid whether the given token is valid or not

      let params = new URLSearchParams(window.location.search)

    auth.verifyToken(
    id: params.get("id"),
    token: params.get("token"),
    )

    Parameters

    • id: string
    • token: string
    • Optional config: Partial<Request>

    Returns Promise<void>

  • withToken can be used to handle authenticated http calls, the callback will receive the current access token. When the request returns a 401, a new access token will be requested and the request will be retried once.

     let res = await auth.withToken(token => {
    return fetch('api.your.app', {
    headers: {
    'Authorization': `Bearer ${token}`,
    }
    })
    })

    Type Parameters

    • T extends Response

    Parameters

    • fn: ((token: string) => Promise<T>)
        • (token: string): Promise<T>
        • Parameters

          • token: string

          Returns Promise<T>

    • Optional session: string

    Returns Promise<T>

Generated using TypeDoc