Hey, so I built a simple authentication system with Phoenix.
I make a Post request to my /signup and /login route. The signup route works fine and all the user data (email, pw, username) is saved in the database.
But when trying to sign up (with correct data) I get “Access to fetch at ‘http://localhost:4000/login’ has been blocked by CORS policy”. My frontend is Port 3000, my phoenix backend is Port 4000. I already added cors to my router, tho here is my router.
defmodule TestWeb.Router do
use TestWeb, :router
pipeline :api do
plug TestWeb.Plugs.RateLimiter
plug CORSPlug, origin: "*"
plug :accepts, ["json"]
plug TestWeb.Plugs.AuthPlug
end
scope "/", TestWeb do
pipe_through :api
post "/login", UserController, :login
post "/signup", UserController, :signup
get "/test", UserController, :test
# CORS
options "/login", UserController, :login
options "/signup", UserController, :signup
options "/test", UserController, :test
end
end
If needed, here is how the whole thing works WianFjr8O8 | SourceBin