1
0

More than 1 year has passed since last update.

Rails APIでFirebase認証を行う

Posted at

概要

firebase-auth-railsというgemを使い、rails/apiモードでfirebase認証をセットアップする時の流れについてです。
Dockerで開発環境を作っています。

Docker側

(api部分)
environment:
   REDIS_URL: redis://redis:6379/0
redis:
    image: redis
    ports:
      - 6379:6379
    volumes:
      - "./app/redis:/data"

rails側

gem 'firebase-auth-rails'
 bundle install
config/initializers/firebase_auth_initializer.rb
FirebaseIdToken.configure do |config|
  config.redis = Redis.new
  config.project_ids = ['あなたのfirebase_project_id']
end
db/migrate/xxxxxxxxxxxxxx_add_uid_to_users.rb
class AddUidToUsers < ActiveRecord::Migration[5.1]
  def change
    add_column :users, :uid, :string
  end
end
rails db:migrate
application_controller.rb
class ApplicationController < ActionController::API
  include Firebase::Auth::Authenticable
  before_action :authenticate_user
end

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0