Ash Authentication in Phoenix Liveviews
I am trying to implement the authentication in liveviews. can anyone provide me a helpful link?
33 Replies
GitHub
ash_authentication_phoenix/dev at main · team-alembic/ash_authentic...
Drop-in authentication support for Phoenix apps using AshAuthentication. - ash_authentication_phoenix/dev at main · team-alembic/ash_authentication_phoenix
GitHub
GitHub - axelbdt/ash_authentication_phoenix_example: The simplest p...
The simplest password authentication with Ash Framework, Ash Authentication and Phoenix. - GitHub - axelbdt/ash_authentication_phoenix_example: The simplest password authentication with Ash Framewo...
i have followed the second one but unfortunately when i hit this path
http://localhost:4000/auth/user/password/register
it gives me the below error no "failure" html template defined for DummyWeb.AuthHTML
@Zach Daniel i am having this page while hitting the
/sign-in
route. There are no fields here. What could be the issue?
What does the
authentication
section look like on your user?scope "/" do
pipe_through :browser
sign_in_route
sign_out_route DummyWeb.AuthController
auth_routes_for(Dummy.Accounts.User, to: DummyWeb.AuthController)
end
If you are asking about the scope in router.exNo, want to see the
Dummy.Accounts.User
Assuming you’ve configured it for authenticationdefmodule Dummy.Accounts.User do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication]
attributes do
uuid_primary_key :id
attribute :name, :string, allow_nil?: false
attribute :email, :ci_string, allow_nil?: false
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
end
authentication do
api Dummy.Accounts
strategies do
password :password do
identity_field :email
end
end
tokens do
enabled? true
token_resource Dummy.Accounts.Token
signing_secret fn _, _ ->
Application.fetch_env(:dummy, :token_signing_secret)
end
end
end
postgres do
table "users"
repo Dummy.Repo
end
identities do
identity :unique_email, [:email]
end
end
I found this in documentationFor code snippets, please surround the text with triple backticks and the word “elixir” for syntax highlighting. For example:
‘’’elixir
code
‘’’
But with backticks instead of quotes.
Do you have a
config :ash_apis, […]
list?
It should be in your root config.exs
``` <- this characterIf you do ```elixir on the first line it will be syntax highlighted

No i didn't do this and it wasn't mentioned in documentation as well 😢
Have you gone through the initial ash getting started guide?
It is assumed for the ash authentication guide that you are familiar with the basics of ash itself
Actually, that isn’t in that guide either
I’ll add this to the getting started guide and to the ash authentication guides
in your_app_web.ex you need to change
helpers: false
to helpers: true
yes just did. Thank you so much
I will let you know if there is any issue 😄
👍 if the current issue has been resolved please add the
solved
tag and then close the thread by right clicking in the sidebar and closing it 🙇Noted
Documentation has been updated, and will reflect on ash_hq with the next release. Thanks 🙂
@Zach Daniel I am unable to register. It says that
How can i generate
token_signing_secret
?
if i disable this in Dummy.Accounts.User
then it works fine. Is it necessary? What is the purpose of this?This stores authentication tokens in the database, which, depending on your setup, you may use for additional features. If you just want log out and log in, you don’t really need it. If you want token revocation, or to have all active sessions tracked in a database, or if you want to send confirmation emails, then you need the token resource set up
Okay then i need it. How can i generate the
token_signing_secret
?
I really appreciate that you are helping me out ❤️You can make a secret value with
mix phx.gen.secret 32
And then you configure it like any other elixir config
config :dummy, :token, signing_secret: your_secret
You should not check that into your repoNoted.
You should use runtime.exs and environment variables
One more thing that if i want a route to be accessed only is the user is authenticated. How can i define that to ash_auth?
You’d do that yourself with phoenix tools
You can see how we do it with live views in ash_hq
So you’d use a plug or a live session on_mount hook
@Zach Daniel I am getting this error now
…could you open a new discussion for that? That one is likely one for @jart
sure