ashok
I want to overwrite the Pow route from
pow_registration_path POST /registration Pow.Phoenix.RegistrationController :create
to
pow_registration_path POST / Pow.Phoenix.RegistrationController :create
So that if visit my website home page it will show registration form which currently visible when I visite URL like example.com/registration/new I have done modification in router.ex as shown below
get “/”, Pow.Phoenix.RegistrationController, :new
and now when I visite my website home page lets say example.com it shows me Pow registration page. If I hit submit without inserting any data in the form field it redirects me the /registration which is the default behavior of Pow my requirement is to redirect to the home page again instead of /register.
I am assuming that it should be done if I will modify my router.ex and overwrite my Pow router there, as shown in the URL: Pow.Phoenix.Router — Pow v1.0.39
but not sure what to pass in it
pow_route(verb, path, plug, plug_opts, options \ )
I do not have idea on params passed like ‘verb’,‘path’,‘plug’,‘plug_opts’,‘options \’ what to pass in them
please suggest how to achieve it. Am I thinking in the correct way? or there will be another way of achieving it.?
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #elixirconf-us
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Kurisu
I think you just need to set as well a path in your router for the
createaction.Here is how I did it:
Just replace “/compte/inscription” by whatever you want to show up as registration url in the browser. That would be “/” in your case.
ashok
Thanks for the solution I will try this. Also I have found that by default after registration Pow registration move back me to home page which in my case is the registration page. How can I redirect user to another page instead of home page. Let’s for example a thank you page or a user dashboard. This may help me to overcome route infinite loop.
danschultzer
You can handle it with a custom callback routes module:
Add
routes_backend: MyAppWeb.Pow.Routesto your configuration.ashok
Thanks for the suggestion I have now took another approach and successfully created what I need by taking the reference from the URL: Custom controllers — Pow v1.0.39
I did registration and login successfully but when I tried to logout it shows me error on the URL: http://localhost:4000/logout
Following are the details of the code
my routes path are:
signup_path GET / MyAppWeb.RegistrationController :new
signup_path POST / MyAppWeb.RegistrationController :create
login_path GET /login MyAppWeb.SessionController :new
login_path POST /login MyAppWeb.SessionController :create
logout_path DELETE /logout MyAppWeb.SessionController :delete
game_path GET /game MyAppWeb.PageController :index
websocket WS /socket/websocket MyAppWeb.UserSocket
In layout/templates/app.html.eex, the code for logout link is below:
In my lib/my_app_web/controllers/session_controller.ex , the code to logout user is
def delete(conn, _params) do
{:ok, conn} = Pow.Plug.clear_authenticated_user(conn)
end
After click on logout it shows me error on the URL: http://localhost:4000/logout
[error] pid<0.461.0> running MyAppWeb.Endpoint (connection pid<0.452.0>, stream id 3) terminated
Server: localhost:4000 (http)
Request: POST /logout
** (exit) an exception was raised:
** (ArgumentError) no function clause for MyAppWeb.Router.Helpers.login_path/2 and action :index. The following actions/clauses are supported:
Please suggest how can redirect user to login page without any error.
Kurisu
To redirect to the login page the expected action is
:newand not:index.So you should write
redirect(conn, to: Routes.login_path(conn, :new))Unless it is really necessary, I think custom controllers are last resort.
ashok
Thanks for the quick solution it worked for this project. Actually I have the same clone of the project which has a similar code but not working in the clone.
Following are the details of the code
My routes path are:
signup_path GET / MyDemoWeb.RegistrationController :new
signup_path POST / MyDemoWeb.RegistrationController :create
login_path GET /login MyDemoWeb.SessionController :new
login_path POST /login MyDemoWeb.SessionController :create
logout_path DELETE /logout MyDemoWeb.SessionController :delete
game_path GET /game MyDemoWeb.PageController :index
websocket WS /socket/websocket MyDemoWeb.UserSocket
In layout/templates/app.html.eex, the code for logout link is below:
In my lib/my_demo_web/controllers/session_controller.ex , the code to logout user is
def delete(conn, _params) do
{:ok, conn} = Pow.Plug.clear_authenticated_user(conn)
end
After click on logout link, it shows me error on the URL: http://localhost:4000/logout
[info] GET /logout
[debug] (Phoenix.Router.NoRouteError) no route found for GET /logout (MyDemoWeb.Router)
How can I get rid of this GET method I need DELETE method here too as in previous project
NOTE: In the second project besides “npm” I have installed “Yarn” and “Webpack” in this project. I am using Mac OS for this project. Webpack also showing error when I have started my server via command
mix phx.server.
The web pack error is shown below:
webpack is watching the files…
Hash: aaf6f65cd61af081c515
Version: webpack 4.41.0
Time: 1096ms
Built at: 10/05/2019 10:34:22 AM
Asset Size Chunks Chunk Names
../favicon.ico 1.23 KiB [emitted]
../images/bitmap.jpg 1.31 MiB [emitted]
../images/g.png 62.6 KiB [emitted]
../images/icon-check.png 676 bytes [emitted]
../images/phoenix.png 13.6 KiB [emitted]
../images/play-icon.png 17.4 KiB [emitted]
../images/user.jpg 31.9 KiB [emitted]
../images/user.png 44.5 KiB [emitted]
../robots.txt 202 bytes [emitted]
app.js 9.96 KiB ./js/app.js [emitted] ./js/app.js
Entrypoint ./js/app.js = app.js
[0] multi ./js/app.js 28 bytes {./js/app.js} [built]
[./css/main.scss] 1.75 KiB {./js/app.js} [built] [failed] [1 error]
[./js/app.js] 495 bytes {./js/app.js} [built]
+ 1 hidden module
ERROR in ./css/main.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleParseError: Module parse failed: Unexpected character ‘?’ (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See Concepts | webpack
Is yarn or webpack error causing any issue in HTML to accept DELETE method I have used in logout link. How can I sort out this issue.
Kurisu
You’re probably right. Sorry but I am not really experienced with webpack to help you find what is wrongly configured but I think that must be fixed first. Good luck.
ashok
[SOLVED] When I modified the issue in webpack-loader