sitefox.auth

Built-in authentication wrapping passport.js - email/password based authentication is supported out of the box:

  (auth/setup-auth app)
  (auth/setup-email-based-auth app template "main")
  (auth/setup-reset-password app template "main")

add-messages!

(add-messages! req messages)

Add messages to be displayed during the authentication process.

callback:reset-password-email

(callback:reset-password-email req verify-url)

callback:sign-up-email

(callback:sign-up-email req verify-url)

component:error

(component:error errors k)

Reagent component to display an error message for a field validation error.

component:messages

(component:messages req)

Reagent component to display messages related to authentication.

component:reset-password-email-form

(component:reset-password-email-form req)

component:reset-password-email-form-done

(component:reset-password-email-form-done req)

component:reset-password-form

(component:reset-password-form req)

component:sign-in-form

(component:sign-in-form req)

component:sign-up-form

(component:sign-up-form req)

component:sign-up-form-done

(component:sign-up-form-done req)

component:sign-up-success

(component:sign-up-success _req)

component:simple-message

(component:simple-message req)

Reagent component to display messages related to authentication.

create-user

(create-user auth-key-type auth-key & [user-data])

Creates a new user object in the user’s kv table. Creates a lookup from auth-key to user-id for convenient retrieval using get-user-by-key.

decrypt-for-transit

(decrypt-for-transit encrypted)

Decrypts a piece of data using symmetric key cryptography and the server’s own secret.

deserialize-user

(deserialize-user user cb)

Internal function used by passport to retrieve the user’s full data from the session.

encrypt-for-transit

(encrypt-for-transit materials)

Encrypts a piece of data for transit using symmetric key cryptography and the server’s own secret.

get-or-create-user-by-key

(get-or-create-user-by-key auth-key-type auth-key & [user-data])

Try to find a user object by it’s auth-key (i.e. username/email) and create a new user with that auth-key if it can’t be found.

get-user-by-key

(get-user-by-key auth-key-type auth-key)

Get a user object from the user’s kv table. The auth-key is the lookup token such as email or username.

hash-password

(hash-password pw & [salt])

Hash a password for storage in a database. If salt (hex string) is not supplied it will be generated (it should be passed when comparing but not when generating).

make-handle-csrf-error

(make-handle-csrf-error template)

Make an error handling page for CSRF errors.

make-hmac-token

(make-hmac-token secret size & materials)

Create an HMAC token to be used for verifying data was generated by the server and is unmodified.

make-middleware:reset-password-send-email

(make-middleware:reset-password-send-email reset-password-email-component email-subject from-address)

make-middleware:sign-up-email

(make-middleware:sign-up-email email-view-component email-subject from-address)

make-middleware:signed-in-redirect

(make-middleware:signed-in-redirect redirect-url)

middleware:finalize-sign-up

(middleware:finalize-sign-up req _res done)

middleware:reset-password-email-submit

(middleware:reset-password-email-submit req _res done)

middleware:reset-password-submit

(middleware:reset-password-submit req _res done)

middleware:sign-in-submit

(middleware:sign-in-submit req res done)

middleware:sign-up-submit

(middleware:sign-up-submit req _res done)

middleware:update-password

(middleware:update-password req _res done)

middleware:verify-reset-password

(middleware:verify-reset-password req _res done)

middleware:verify-sign-up

(middleware:verify-sign-up req _res done)

re-plus

re-slash

save-user

(save-user user-data)

Persist a user object back into the users kv table, overwriting the existing object.

serialize-user

(serialize-user user cb)

Internal function used by passport to store a user reference in the session.

setup-auth

(setup-auth app & [sign-out-redirect-url])

Set up passport based authentication. The sign-out-redirect-url defaults to ‘/’. You may also pass ?next=RELATIVE-URL to dynamically set the redirect URL.

setup-email-based-auth

(setup-email-based-auth app template selector & {:keys [sign-in-redirect sign-in-form-component sign-up-redirect sign-up-email-callback sign-up-email-subject sign-up-from-address sign-up-form-component sign-up-form-done-component simple-message-component]})

Set up passport email based authentication with all of the required forms and views. Pass in an HTML template string and selector where the auth UI should be be mounted.

You can override various aspects of the UI using these keys:

  • :sign-in-redirect is the URL to redirect to after signing in (defaults to /).
  • :sign-up-redirect is the URL to redirect to after signing up successfully (defaults to /).
  • :sign-in-form-component is a Reagent component to render the sign-in form (defaults to component:sign-in-form).
  • :sign-up-email-callback is a function used to render the sign-up validation email (defaults to callback:sign-up-email reagent form). The function will be passed req (express request object) and verify-url as arguments and may return a Reagent form or an HTML string.
  • :sign-up-email-subject the subject line of the sign up verification email (defaults to req.hostname + signup email.).
  • :sign-up-from-address the ‘From’ address where the email originates from (defaults to FROM_ADDRESS env var).
  • :sign-up-form-component is a Reagent component to render the sign-up form (defaults to component:sign-up-form).
  • :sign-up-form-done-component is a Reagent component to render the sign-up done page (defaults to component:sign-up-form-done).
  • :simple-message-component is a Reagent component to render error messages during the verification stage (defaults to component:simple-message).

setup-reset-password

(setup-reset-password app template selector & {:keys [reset-password-redirect reset-password-email-subject reset-password-from-address reset-password-email-callback reset-password-email-form-component reset-password-email-form-done-component reset-password-form-component simple-message-component]})

Add a ‘reset password’ flow to the app. Covers both ‘change password’ and ‘forgot password’ functionality. Pass in an HTML template string and selector where the auth UI should be mounted.

You can override various aspects of the UI using these keys:

  • :reset-password-redirect is the URL to redirect to after the password has been reset successfully (defaults to /).
  • :reset-password-email-subject the subject line of the reset password email (defaults to req.hostname + reset password link.).
  • :reset-password-from-address the ‘From’ address where the email originates from (defaults to FROM_ADDRESS env var).
  • :reset-password-email-callback is a function used to render the reset password validation email (defaults to callback:reset-password-email reagent form). The function will be passed req (express request object) and verify-url as arguments and may return a Reagent form or an HTML string.
  • :reset-password-email-form-component is a Reagent component to render the reset-password email form (defaults to component:reset-password-email-form).
  • :reset-password-email-form-done-component is a Reagent component to render the final page of the reset password flow (defaults to component:reset-password-email-form-done).
  • :reset-password-form-component is a Reagent component to render the reset-password form (defaults to component:reset-password-form).
  • :simple-message-component is a Reagent component to render error messages during the password reset process (defaults to component:simple-message-component).

timestamp-expired?

(timestamp-expired? time-stamp milliseconds)

Check if a timestamp (ms) has expired.

validate-post-data

(validate-post-data req fields & [warnings])

Uses node-input-validator to validated post data and returns any validation errors. fields is a structure following the input validator format like: {:email ["required" "email"]}. warnings is similarly a structure overriding the default warnings like: {:email "You must supply a valid email address"}.

verify-kv-email-user

(verify-kv-email-user email password cb)

Verify the user’s supplied email and password against that in the database.