benonymus

benonymus

Hey there,

I added social media logins (fb, g) and here is the flow
user click on login with fb button on client and calls /auth/facebook
gets redirected to facebook logs in
response from facebook comes to the backend to /auth/facebook/callback
i create a user and log him in
and send the user back in the json response as with the normal login
but the problem is that with the response the client is not on the original page, but on a link to the backend
how can this be done in a way that the user stays on the client page?

Showing Posts 1 to 10

wolfiton

wolfiton

Hey,

Please calrify this:

So you are using phoenix in api mode?

What client are you using react vue angular ember?

Or are you using phoenix with views ?

benonymus

benonymus OP

The client is vue but would also be an ios and android
I am using phoenix with json views

wolfiton

wolfiton

I think you will have to redirect the user your desired page after the login.

Also are you using absinthe?

benonymus

benonymus OP

no i don’t
but the problem is the redirect, I am sending a json response, with the logged in user
but it shows up in the browser as a page of json from a link that points to the server from facebook or google and looks like this:

http://localhost:4000/auth/google/callback?code=4/idsaasGUxia0zA-zJpyJuR3Rl4FI9p6QV7cIH155gEJ4SXFbQmCpGi0dTcwYOuhzBfR0R80zlGB78KQSH9pV3nwc&scope=email+profile+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile&authuser=0&session_state=94ec4fa79800647bedfe1ab561ef53f771ef6831..3638&prompt=none

wolfiton

wolfiton

Can you share some code on where you think is the problem, maybe where you create a the login and also the mix.exs file to see what packages you are using?

benonymus

benonymus OP

maybe i was not clear, the problem is to how to get back to the client page at the end instead of landing on the page of the server.
I don’t know how to tackle the issue

  def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
    user = basic_info(auth)

    with(
      resource = %User{} <-
        get_or_create_user(user),
      {:ok, token, _} <-
        Guardian.encode_and_sign(
          resource,
          %{},
          key: :user,
          permissions: %{user: GPermissions.max()}
        )
    ) do
      resource = Accounts.add_categories_from_settings(resource)

      unread_uninteracted_invitations_counts =
        Notifications.return_unread_uninteracted_invitations_counts(resource)

      conn
      |> put_status(200)
      |> put_view(AuthView)
      |> render(
        "logged_in.json",
        message: "Logged in!",
        token: token,
        user: resource,
        notis: unread_uninteracted_invitations_counts
      )
    else
      _ ->
        conn
        |> put_status(401)
        |> put_view(ErrorView)
        |> render("401.json", message: "Failed to authenticate.", errors: nil)
    end
  end

it is working as expected all, just that is it possible and if yes how to end up back on the client page

deps:

`      {:postgrex, "~> 0.14"},
      {:ecto, "~> 3.0.9"},
      {:comeonin, "~> 5.1"},
      {:argon2_elixir, "~> 2.0"},
      {:ueberauth, "~> 0.5"},
      {:ueberauth_identity, "~> 0.2"},
      {:guardian, "~> 1.2"},
      {:guardian_db, "~> 2.0"},
      {:arc, "~> 0.11"},
      {:arc_ecto, "~> 0.11"},
      {:trans, "~> 2.0"},
      {:hashids, "~> 2.0"},
      {:csv, "~> 2.0"},
      {:ex_aws, "~> 2.0", override: true},
      {:ex_aws_s3, "~> 2.0"},
      {:ex_aws_sns, "~> 2.0"},
      {:ex_aws_ses, "~> 2.0"},
      {:poison, ">= 1.2.0"},
      {:jason, "~> 1.1"},
      {:hackney, "~> 1.9"},
      {:sweet_xml, "~> 0.6"},
      {:word_smith, "~> 0.1.0"},
      {:timex, "~> 3.4"},
      {:ex_phone_number, "~> 0.1"},
      {:quantum, "~> 2.3"},
      {:gettext, "~> 0.14"},
      {:elixir_uuid, "~> 1.2"},
      {:ecto_autoslug_field, "~> 1.0"},
      {:ueberauth_google, "~> 0.8"},
      {:ueberauth_facebook, "~> 0.8"},
      {:bypass, "~> 1.0", only: :test}`
wolfiton

wolfiton

Let;s try this

Instead of render replace with redirect(to: “/”)

conn
      |> put_status(200)
      |> put_view(AuthView)
      |> redirect(to: "/")

This should redirect on succesfull auth to the / home page.

benonymus

benonymus OP

well that is something, but we are not really ahead with that because we are still in the realm of the server, this would take us to the homepage of the server, not the client, and no user anymore obviously

wolfiton

wolfiton

Can vue read the json from your backend in a component?

Do you see them connected?

Also i assume that your vue is on :8080 and your server on 4000 ports?

benonymus

benonymus OP

they are on separate hosts, not connected
for this: Can vue read the json from your backend in a component?
i am not sure, i am not working on the vue project, but I am sending the exact same response in the usual login flow and there are no problem there at all, the issue here seems to be that because the facebook login opens in the same window as the app it doesnt get back to the app/client

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews