Ruby on Rails
Add authentication to your Rails app with Clowk in 5 minutes
Install the gem
gem 'clowk'bundle installConfigure
Clowk.configure do |config|
config.publishable_key = ENV['CLOWK_PUBLISHABLE_KEY']
config.secret_key = ENV['CLOWK_SECRET_KEY']
endCLOWK_PUBLISHABLE_KEY=pk_live_...
CLOWK_SECRET_KEY=sk_live_...Mount the engine
Rails.application.routes.draw do
mount Clowk::Engine => '/clowk'
endThis adds /clowk/sign_in, /clowk/sign_up, /clowk/sign_out, and /clowk/oauth/callback.
Include Authenticable
class ApplicationController < ActionController::Base
include Clowk::Authenticable
endProtect your controllers
class DashboardController < ApplicationController
before_action :authenticate_clowk!
def index
@user = current_clowk
end
endauthenticate_clowk! verifies the JWT from the session. If invalid, it redirects to the Clowk sign-in page (or returns 401 for JSON requests).
current_clowk returns a Clowk::Current object:
current_clowk.id # User UUID
current_clowk.email # "jane@example.com"
current_clowk.name # "Jane Doe"
current_clowk.avatar_url # "https://..."
current_clowk.provider # "google"Protect specific actions
class PostsController < ApplicationController
before_action :authenticate_clowk!, only: [:create, :update, :destroy]
def index
@posts = Post.all
end
def create
@post = Post.create!(
title: params[:title],
author_email: current_clowk.email,
author_id: current_clowk.id
)
redirect_to @post
end
endAPI-only controllers
class Api::V1::BaseController < ActionController::API
include Clowk::Authenticable
before_action :authenticate_clowk!
endViews with Hotwire & Turbo
<nav>
<% if clowk_signed_in? %>
<span>Hello, <%= current_clowk.name %></span>
<%= link_to "Sign out", clowk.sign_out_path, data: { turbo_method: :delete } %>
<% else %>
<%= link_to "Sign in", clowk.sign_in_path %>
<%= link_to "Sign up", clowk.sign_up_path %>
<% end %>
</nav>Next steps
- Full Rails integration — all configuration options, SDK client, and advanced usage
- How authentication works — the OAuth flow in detail