All Projects → promptworks → guardian_trackable

promptworks / guardian_trackable

Licence: MIT license
A Guardian hook to track user sign ins.

Programming Languages

elixir
2628 projects
HTML
75241 projects

Projects that are alternatives of or similar to guardian trackable

Guardian
Elixir Authentication
Stars: ✭ 3,150 (+12500%)
Mutual labels:  phoenix, guardian, plug
Absinthe plug
Plug support for Absinthe, the GraphQL toolkit for Elixir
Stars: ✭ 209 (+736%)
Mutual labels:  phoenix, plug
Formex
A better form library for Phoenix
Stars: ✭ 206 (+724%)
Mutual labels:  phoenix, ecto
alternate
Plug and Phoenix helpers to localize your web app via the URL
Stars: ✭ 26 (+4%)
Mutual labels:  phoenix, plug
Logster
Easily parsable single line, plain text and JSON logger for Plug and Phoenix applications
Stars: ✭ 171 (+584%)
Mutual labels:  phoenix, plug
Appsignal Elixir
🟪 AppSignal for Elixir package
Stars: ✭ 176 (+604%)
Mutual labels:  phoenix, plug
query builder
Compose Ecto queries without effort
Stars: ✭ 56 (+124%)
Mutual labels:  phoenix, ecto
Filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL.
Stars: ✭ 83 (+232%)
Mutual labels:  phoenix, ecto
phoenix pagination
Simple pagination for Ecto and Phoenix that uses plain EEx templates.
Stars: ✭ 20 (-20%)
Mutual labels:  phoenix, ecto
querie
Compose Ecto query from the client side
Stars: ✭ 20 (-20%)
Mutual labels:  phoenix, ecto
ecto profiler
Project for Ecto DB profiling
Stars: ✭ 16 (-36%)
Mutual labels:  phoenix, ecto
Phoenix Ecto Encryption Example
🔐 A detailed example for how to encrypt data in a Phoenix (Elixir) App before inserting into a database using Ecto Types
Stars: ✭ 166 (+564%)
Mutual labels:  phoenix, ecto
Mipha
Proj Elixir Forum build with phoenix 1.5.
Stars: ✭ 153 (+512%)
Mutual labels:  phoenix, ecto
ecto nested changeset
Helpers for manipulating nested Ecto changesets
Stars: ✭ 23 (-8%)
Mutual labels:  phoenix, ecto
Phoenix live dashboard
Realtime dashboard with metrics, request logging, plus storage, OS and VM insights
Stars: ✭ 1,657 (+6528%)
Mutual labels:  phoenix, ecto
Params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters.
Stars: ✭ 239 (+856%)
Mutual labels:  phoenix, ecto
phoenix-client-ssl
Set of Plugs / Lib to help with SSL Client Auth.
Stars: ✭ 18 (-28%)
Mutual labels:  phoenix, plug
Authex
Authex is an opinionated JWT authentication and authorization library for Elixir.
Stars: ✭ 73 (+192%)
Mutual labels:  phoenix, plug
Polymorphic embed
Polymorphic embeds in Ecto
Stars: ✭ 80 (+220%)
Mutual labels:  phoenix, ecto
algoliax
Algolia integration to elixir application
Stars: ✭ 38 (+52%)
Mutual labels:  phoenix, ecto

GuardianTrackable Build Status

A Guardian hook to track user sign in. Tracks the following values:

  • sign_in_count - Increased every time a sign in is made
  • current_sign_in_at - A timestamp updated when the user signs in
  • last_sign_in_at - Holds the timestamp of the previous sign in
  • current_sign_in_ip - The remote ip updated when the user sign in
  • last_sign_in_ip - Holds the remote ip of the previous sign in

Installation

The package can be installed by adding guardian_trackable to your list of dependencies in mix.exs:

def deps do
  [
    {:guardian_trackable, "~> 0.2.0"}
  ]
end

Use version 0.1.1 if you need Ecto 2.x support.

Usage

First, you'll need to add the columns for tracking to your table. You can generate the migration using Mix:

mix guardian_trackable.install

Alternatively, you can create it manually:

def change do
  alter table(:users) do
    add :sign_in_count, :integer, default: 0
    add :last_sign_in_ip, :string
    add :last_sign_in_at, :utc_datetime
    add :current_sign_in_ip, :string
    add :current_sign_in_at, :utc_datetime
  end
end

To use it, you'll need to setup your schema like this:

defmodule MyApp.User do
  use Ecto.Schema
  use GuardianTrackable.Schema

  schema "users" do
    field :email, :string
    guardian_trackable()
  end
end

Then, you can add the following configuration to your Guardian module:

defmodule MyApp.Guardian do
  use Guardian, otp_app: :my_app

  @impl true
  def after_sign_in(conn, resource, _token, _claims, _opts) do
    GuardianTrackable.track!(MyApp.Repo, resource, conn.remote_ip)
    {:ok, conn}
  end
end

Running tests

Before you can run the tests, you'll need to setup a database:

$ mix ecto.setup

Now, run the tests:

$ mix test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].