tino415

tino415

Opinions for projects and architecture

Hello all,

after some years working with elixir, there are still some situations I don’t know how to clearly resolve, thinking about putting together some best practices for ecto and other tools. To make it easy I decided to start project and simply document all issues I came along. Besides that I’m also trying a lot of stuff (using plug and ecto without phoenix, schemas folder instead of domain driven design style). So I’m asking here for opinion, maybe some constructive critics etc GitHub - tino415/authex: Simple API only OAuth2/OpenID server · GitHub. So far I stumble on these:

  • I’m trying to follow CQRS and also to use changeset for most casting and validation
    but I think these things sometimes get in conflict. In this case I got to conflict
    when I was trying to validate creation of token. Because, in case o refresh token,
    I need casted refresh token from data to retrieve previous token to verify it validity,
    I resolved to what I always does, basically manually cast it in action (sort of controller)
    and pass selected token to changeset.

    Action:

    @impl true
    def create(conn, %{"code" => code} = params) do
      with %{} = flow <- Authex.get_flow_by_code_without_token(code) do
        do_create(conn, flow, params)
      else
        nil -> View.unauthorized(conn)
      end
    end
    
    def create(conn, %{"refresh_token" => refresh_token} = params) do
      with %{} = flow <- Authex.get_flow_by_refresh_token(refresh_token) do
        do_create(conn, flow, params)
      else
        nil -> View.unauthorized(conn)
      end
    end
    
    def create(conn, body_params) do
      do_create(conn, nil, body_params)
    end
    
  • I always tried to use put_assoc so result after inserting contains that association and
    I don’t need to return associated entity separately, but in this project it does not
    work. So I have this line after updating token:

      |> case do
        {:ok, client} -> {:ok, Repo.preload(client, scopes: :scope)}
        r -> r
      end
    

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

We're in Beta

About us Mission Statement