Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to enable access to session and page assigns within Beacon page and layout content? #643

Open
matthewsinclair opened this issue Nov 11, 2024 · 0 comments

Comments

@matthewsinclair
Copy link

Context

I am working on a project that uses Elixir, Phoenix, and Ash and I want to integrate Beacon as my CMS to enable content editing for certain pages on the deployed app without having to worry about rebuilding and redeploying.

For this to work, I need a way to be able to get access to the assigns variable for the session (and possibly the page as well, but that is less important for now). This is so that I can see things like the currently logged in user (via ash_authentication) and have access to other Ash features, too.

At the moment, there is an issue when specifying routes that are handled by beacon_site as they do not work if there are any extra params to the scope command in router.ex.

So, for example, this will work:

  scope "/" do
    pipe_through [:browser]
    beacon_site "/ms", site: :ms
    beacon_site "/qfm", site: :qfm
  end

But this will not:

  scope "/", MscmsWeb do
    pipe_through :browser

    get "/", PageController, :home
    beacon_site "/ms", site: :ms
    beacon_site "/qfm", site: :qfm

If I try the above, I get the following compilation error:

$ mix compile
Compiling 1 file (.ex)
     error: undefined function forward/3 (there is no such import)168forward path, AshAuthentication.Phoenix.StrategyRouter,
     │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     │
     └─ deps/ash_authentication_phoenix/lib/ash_authentication_phoenix/router.ex:168: MscmsWeb.Router (module)


== Compilation error in file lib/mscms_web/router.ex ==
** (CompileError) lib/mscms_web/router.ex: cannot compile module MscmsWeb.Router (errors have been logged)
    (stdlib 6.1.2) lists.erl:2343: :lists.mapfoldl_1/3
    (phoenix 1.7.14) expanding macro: Phoenix.Router.scope/3
    lib/mscms_web/router.ex:62: MscmsWeb.Router (module)

Which I guess is because beacon_site is not defined for the MscmsWeb scope. But I would be the first to admit that I really have no idea, as I'm just guessing ... :)

In the above example, I need to run those beacon_site calls thru the scope with the MscmsWeb parameters as that is where all of the Ash goodies are invoked. For example, if I wanted to ensure that some parts of the Beacon pages are only accessible to a logged in user, I'd need to run them through that scope, and then on some of the Beacon pages I'd need to be able to inspect the session for :current_user in assigns.

Ash and Beacon are both great pieces of software so it would be excellent if I was able to use them together.

Additional Context

There is long discussion on this feature on the #beacon_cms channel on the Elixir Slack, which you can see here:
https://elixir-lang.slack.com/archives/C02T04D147M/p1731262689149579

Environment

  • Elixir version (elixir -v): Erlang/OTP 27 [erts-15.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace] -- Elixir 1.17.3 (compiled with Erlang/OTP 26)
  • Phoenix version (mix deps): phoenix 1.7.14
  • Phoenix LiveView version (mix deps): phoenix_live_view 1.0.0-rc.7
  • Beacon version (mix deps): beacon 0.2.0
  • Operating system: Sequoia 15.1
  • Browsers on which you attempted to reproduce this bug (the more the merrier): Chrome, Safari
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant