Magic Link

Email one-time sign-in links.

This page documents the current Ruby port behavior. Ruby uses snake_case option names and auth.api method names; HTTP paths and JSON keys keep the upstream wire shape where implemented.

Configure

config/auth.rb
require "better_auth"

auth = BetterAuth.auth(
  secret: ENV.fetch("BETTER_AUTH_SECRET"),
  base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
  plugins: [
    BetterAuth::Plugins.magic_link(send_magic_link: ->(data, _ctx = nil) { Mailer.magic_link(data[:email], data[:url]).deliver_now })
  ]
)

Usage

server.rb
auth.api.sign_in_magic_link(body: { email: "ada@example.com", callbackURL: "/dashboard" })
status, headers, body = auth.api.magic_link_verify(query: { token: params[:token] }, as_response: true)

Routes

MethodPathRuby API method
POST/sign-in/magic-linkauth.api.sign_in_magic_link
GET/magic-link/verifyauth.api.magic_link_verify

Options

Current Ruby options accepted by BetterAuth::Plugins.magic_link:

  • expires_in
  • send_magic_link
  • disable_sign_up
  • generate_token
  • store_token

Support Notes

  • The examples above are based on Ruby plugin source and tests in packages/better_auth.
  • If an upstream section is not represented here, treat it as not yet documented or not yet supported by the Ruby port until the matching Ruby implementation exists.

On this page