Skip to content

Commit

Permalink
Add user modelo simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Pablo Gil committed Oct 26, 2022
1 parent 3988a9e commit 0e47fe7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/generators/auth/templates/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

#= User
#
# A person who has an account on the site (via Google Cloud Identity Platform).
class User < ApplicationRecord
validates :identity_platform_id, presence: true, uniqueness: true

def self.from_identity_token(token)
return unless token.valid?

find_or_initialize_by(identity_platform_id: token.subject).tap do |user|
user.update! token.payload.slice(:name, :email)
end
end
end
16 changes: 16 additions & 0 deletions lib/generators/auth/templates/models/user_migration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :email
t.string :name
t.string :identity_platform_id, null: false

t.timestamps

t.index %i[identity_platform_id], name: :UK_user_identity_platform, unique: true
end
end
end

0 comments on commit 0e47fe7

Please sign in to comment.