Code Monkey home page Code Monkey logo

Comments (8)

riverrun avatar riverrun commented on August 24, 2024 1

To start off with, we could add this to the documentation, or the wiki, as an example of how you can extend the Remember plug. After that, we can discuss whether we want to add it to the default implementation.

from phauxth.

todotentei avatar todotentei commented on August 24, 2024

I wrote some more here. I want to set default :enable_cookie_management config to false. And if anyone want to use it, they can set it to true and follow some instructions.

from phauxth.

riverrun avatar riverrun commented on August 24, 2024

Thanks - I'll take a look at that later and get back to you soon.

from phauxth.

todotentei avatar todotentei commented on August 24, 2024

I think this simplest way to enable_cookie_management:

In Phauxth.Config, add:

def enable_cookie_management  do
  Application.get_env(:phauxth, :enable_cookie_management, false)
end

In Phauxth.Remember, add:

def init(opts) do
  {
    {
      Keyword.get(opts, :max_age, @max_age),
      Keyword.get(opts, :user_context, Config.user_context()),
      Keyword.get(opts, :enable_cookie_management, Config.enable_cookie_management()),
      opts
    },
    Keyword.get(opts, :log_meta, [])
  }
end

def get_user(conn, token, {max_age, user_context, false, opts}) do
  with {:ok, user_id} <- Token.verify(conn, token, max_age, opts) do
    user_context.get(user_id)
  end
end

def get_user(conn, token, {max_age, user_context, true, opts}) do
  with {:ok, user_id} <- Token.verify(conn, token, max_age, opts)
       %{cookies: cookies} = user <- user_context.get(user_id),
       true <- Map.has_key?(cookies, token),
  do
    user
  end
end

So, if get_user returns nil, then call delete_rem_cookie/1

from phauxth.

riverrun avatar riverrun commented on August 24, 2024

@virayatta I have added a related issue - #81 , which is based on the version 2.0 implementation.

from phauxth.

riverrun avatar riverrun commented on August 24, 2024

The latest version calls delete_rem_cookie by default - after it sees that the cookie / token is invalid.

Can we close this issue, or is there anything else you want to add?

from phauxth.

todotentei avatar todotentei commented on August 24, 2024

from phauxth.

riverrun avatar riverrun commented on August 24, 2024

I'll close it for now, and if you want to reopen it later, that's fine.

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.