Code Monkey home page Code Monkey logo

Comments (6)

riverrun avatar riverrun commented on August 24, 2024

Could you check to see if the current_user is being set for the protected resource? You can do this by running IO.inspect conn.assigns in the controller function of the protected resource.

from phauxth.

beckler avatar beckler commented on August 24, 2024

Okay, so here's the output logs when I initially reach a protected resource the first time:

[info] GET /accounts/user
[debug] Processing with DownstageWeb.Account.UserController.index/2
  Parameters: %{}
  Pipelines: [:browser, :protected]
[debug] QUERY OK source="sessions" db=2.4ms queue=0.1ms
SELECT s0."id", s0."expires_at", s0."user_id", s0."inserted_at", s0."updated_at" FROM "sessions" AS s0 WHERE (s0."expires_at" > $1) AND (s0."id" = $2) [~U[2019-09-12 13:08:22Z], <<196, 143, 2, 242, 161, 76, 74, 34, 173, 20, 79, 243, 152, 92, 83, 224>>]
[debug] QUERY OK source="users" db=2.0ms
SELECT u0."id", u0."email", u0."password_hash", u0."confirmed_at", u0."reset_sent_at", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."id" = $1) [<<71, 42, 202, 165, 20, 187, 71, 76, 132, 210, 192, 135, 147, 242, 224, 186>>]
%{
  current_user: %{
    __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
    __struct__: Downstage.Accounts.User,
    companies: #Ecto.Association.NotLoaded<association :companies is not loaded>,
    confirmed_at: ~U[2019-09-03 03:38:03Z],
    email: "[email protected]",
    id: "472acaa5-14bb-474c-84d2-c08793f2e0ba",
    inserted_at: ~N[2019-09-03 03:37:59],
    reset_sent_at: nil,
    sessions: #Ecto.Association.NotLoaded<association :sessions is not loaded>,
    updated_at: ~N[2019-09-03 03:38:03]
  }
}
[info] user=472acaa5-14bb-474c-84d2-c08793f2e0ba message="user authenticated"
[debug] QUERY OK source="users" db=1.2ms
SELECT u0."id", u0."email", u0."password_hash", u0."confirmed_at", u0."reset_sent_at", u0."inserted_at", u0."updated_at" FROM "users" AS u0 []
[info] Sent 200 in 8ms

After I delete the session from the DB, and visit that same endpoint again, here are the produced logs:

[info] GET /accounts/user
[debug] Processing with DownstageWeb.Account.UserController.index/2
  Parameters: %{}
  Pipelines: [:browser, :protected]
[debug] QUERY OK source="sessions" db=0.8ms
SELECT s0."id", s0."expires_at", s0."user_id", s0."inserted_at", s0."updated_at" FROM "sessions" AS s0 WHERE (s0."expires_at" > $1) AND (s0."id" = $2) [~U[2019-09-12 13:08:46Z], <<196, 143, 2, 242, 161, 76, 74, 34, 173, 20, 79, 243, 152, 92, 83, 224>>]
[info] user=nil message="no user found"
[debug] QUERY OK source="users" db=1.0ms queue=0.1ms
SELECT u0."id", u0."email", u0."password_hash", u0."confirmed_at", u0."reset_sent_at", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."id" = $1) [<<71, 42, 202, 165, 20, 187, 71, 76, 132, 210, 192, 135, 147, 242, 224, 186>>]
[info] user=472acaa5-14bb-474c-84d2-c08793f2e0ba message="user authenticated"
[debug] QUERY OK db=5.5ms queue=0.8ms
INSERT INTO "sessions" ("expires_at","user_id","inserted_at","updated_at","id") VALUES ($1,$2,$3,$4,$5) [~U[2019-09-13 13:08:46Z], <<71, 42, 202, 165, 20, 187, 71, 76, 132, 210, 192, 135, 147, 242, 224, 186>>, ~N[2019-09-12 13:08:46], ~N[2019-09-12 13:08:46], <<53, 3, 64, 149, 182, 2, 67, 169, 139, 18, 214, 120, 11, 239, 72, 39>>]
%{
  current_user: %{
    __meta__: #Ecto.Schema.Metadata<:loaded, "users">,
    __struct__: Downstage.Accounts.User,
    companies: #Ecto.Association.NotLoaded<association :companies is not loaded>,
    confirmed_at: ~U[2019-09-03 03:38:03Z],
    email: "[email protected]",
    id: "472acaa5-14bb-474c-84d2-c08793f2e0ba",
    inserted_at: ~N[2019-09-03 03:37:59],
    reset_sent_at: nil,
    sessions: #Ecto.Association.NotLoaded<association :sessions is not loaded>,
    updated_at: ~N[2019-09-03 03:38:03]
  }
}
[debug] QUERY OK source="users" db=1.2ms
SELECT u0."id", u0."email", u0."password_hash", u0."confirmed_at", u0."reset_sent_at", u0."inserted_at", u0."updated_at" FROM "users" AS u0 []
[info] Sent 200 in 12ms

This is just visiting the :index function of this controller, and this is what I have for the plugs in the controller:

  plug :user_check when action in [:index, :show]
  plug :id_check when action in [:edit, :update, :delete]

Looking at the logs now, it does look like it checks the session, but if it can't find the session it looks like it generates a new row in the sessions table.

Since the session keeps getting regenerated, I also tried setting the expires_at field to a date in the past, but it doesn't seem to validate against that either.

from phauxth.

riverrun avatar riverrun commented on August 24, 2024

It would help me debug this if I coud see the code. Is it publicly available?

from phauxth.

beckler avatar beckler commented on August 24, 2024

@riverrun It wasn't but I went ahead and opened it up.

https://github.com/beckler/downstage_umbrella

from phauxth.

riverrun avatar riverrun commented on August 24, 2024

First of all, sorry for the delay in getting back to you - I haven't felt too good the last few days.

I think the issue is that the Phauxth.Remember plug is creating a new session because there is still a remember_me cookie present. Could you check if that is the case by adding IO.inspect conn.req_cookies in the controller function? If a remember_me cookie is there, then it is working as expected, and if not, there is a problem.

from phauxth.

beckler avatar beckler commented on August 24, 2024

Ah okay, the remember_me cookie is probably present then, as I'm fairly certain I have it hard coded it in the default session path.

Thank you for responding! And thank you for this awesome library!

from phauxth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.