{@thread.name}

talha-azeem:

I am trying to implement the authentication in liveviews. can anyone provide me a helpful link?

talha-azeem:

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

talha-azeem:

<@197905764424089601> i am having this page while hitting the /sign-in route. There are no fields here. What could be the issue?

ZachDaniel:

What does the authentication section look like on your user?

talha-azeem:

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.ex

ZachDaniel:

No, want to see the Dummy.Accounts.User

ZachDaniel:

Assuming you’ve configured it for authentication

talha-azeem:

defmodule 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 documentation

ZachDaniel:

For 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.

ZachDaniel:

Do you have a config :ash_apis, […] list?

ZachDaniel:

It should be in your root config.exs

ZachDaniel:

``` <- this character

talha-azeem:

defmodule 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

ZachDaniel:

If you do ```elixir on the first line it will be syntax highlighted

ZachDaniel:

Foo.bar()

talha-azeem:

No i didn’t do this and it wasn’t mentioned in documentation as well 😢

ZachDaniel:

Have you gone through the initial ash getting started guide?

ZachDaniel:

It is assumed for the ash authentication guide that you are familiar with the basics of ash itself

ZachDaniel:

Actually, that isn’t in that guide either

ZachDaniel:

I’ll add this to the getting started guide and to the ash authentication guides

talha-azeem:

UndefinedFunctionError at GET /sign-in
function DummyWeb.Router.Helpers.auth_path/2 is undefined (module DummyWeb.Router.Helpers is not available)

ZachDaniel:

in your_app_web.ex you need to change helpers: false to helpers: true

talha-azeem:

yes just did. Thank you so much

talha-azeem:

I will let you know if there is any issue 😄

ZachDaniel:

👍 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 🙇

talha-azeem:

Noted

ZachDaniel:

Documentation has been updated, and will reflect on ash_hq with the next release. Thanks 🙂

talha-azeem:

<@197905764424089601> I am unable to register. It says that

Missing JWT signing secret. Please see the documentation for `AshAuthentication.Jwt` for details

How can i generate token_signing_secret ?

talha-azeem:

if i disable this in Dummy.Accounts.User

tokens do
      enabled? true
      token_resource Dummy.Accounts.Token
      signing_secret fn _, _ ->
        Application.fetch_env(:dummy, :token_signing_secret)
      end
    end

then it works fine. Is it necessary? What is the purpose of this?

ZachDaniel:

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

talha-azeem:

Okay then i need it. How can i generate the token_signing_secret ?

talha-azeem:

I really appreciate that you are helping me out ❤️

ZachDaniel:

You can make a secret value with mix phx.gen.secret 32

ZachDaniel:

And then you configure it like any other elixir config

ZachDaniel:

config :dummy, :token, signing_secret: your_secret

ZachDaniel:

You should not check that into your repo

talha-azeem:

Noted.

ZachDaniel:

You should use runtime.exs and environment variables

talha-azeem:

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?

ZachDaniel:

You’d do that yourself with phoenix tools

ZachDaniel:

You can see how we do it with live views in ash_hq

ZachDaniel:

So you’d use a plug or a live session on_mount hook

talha-azeem:

<@197905764424089601> I am getting this error now

Couldn't recognize the signer algorithm.
Possible values are:

["HS256", "HS384", "HS512", "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "Ed25519", "Ed25519ph", "Ed448", "Ed448ph"]

ZachDaniel:

…could you open a new discussion for that? That one is likely one for <@346791515923939328>

talha-azeem:

sure