Project

devise_uid

0.03
No release in over 3 years
Low commit activity in last 3 years
Add UID support to Devise
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.12

Runtime

>= 3.0.0
>= 3.0
 Project Readme

devise_uid

Build Status Code Climate Dependency Status

Add UID support to Devise. A lot of times, we want a unique ID representing the user model instead of its incremental ID in the database, for example, in API instead of exposing the primary key, we use a random generated unique string to indentify this user.

Installation

Add this line to your application's Gemfile:

gem 'devise_uid'

And then execute:

$ bundle

Automatic Installation

Add devise_uid to any of your Devise models using the following generator:

rails generate devise_uid MODEL

Replace MODEL with the class name you want to add devise_uid. This will add the :uid flag to your model's Devise modules. The generator will also create a migration file. Currently only ActiveRecord is supported.

Manual Installation

Add :uid to the devise call in your model:

class User < ActiveRecord
  devise :database_authenticable, :confirmable, :uid
end

Add uid field to your Devise model migration:

class AddUidToUser< ActiveRecord::Migration
  add_column :users, :uid, :string
  add_index :users, :uid, :unique => true
end

Usage

An uid is generated when a Devise MODEL is created. Access it like this:

user = User.create(email: "foo@bar.com")
puts user.uid # => "V8aS9tucNzKyH39d4Bpq"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request