remove unused vars/aliases and fix bug where first authentication doesn't decrypt link

This commit is contained in:
Silas 2022-03-01 22:08:53 -05:00
parent 5047ee653b
commit 45bd5ba81a
Signed by: silentsilas
GPG Key ID: 4199EFB7DAA34349
8 changed files with 14 additions and 16 deletions

View File

@ -75,6 +75,10 @@ const AuthPage = (props: AuthPageProps) => {
alert("Could not find intended link in URL"); alert("Could not find intended link in URL");
return null; return null;
} }
if (!user) {
// no need to retrieve link if they weren't authenticated
return null;
}
const linkResponse = await fetch(`/links/${linkId}`); const linkResponse = await fetch(`/links/${linkId}`);
let linkData: IntendedLink | null; let linkData: IntendedLink | null;

View File

@ -95,6 +95,7 @@ const ForPage = (props: ForPageProps) => {
value={serviceSelect} value={serviceSelect}
> >
<option value="github">Github</option> <option value="github">Github</option>
<option value="google">Gmail</option>
</Select> </Select>
<Spacer space="3rem" /> <Spacer space="3rem" />
<SpaceBetweenContainer> <SpaceBetweenContainer>

View File

@ -6,7 +6,6 @@ defmodule Entendu.UserFromAuth do
require Jason require Jason
alias Ueberauth.Auth alias Ueberauth.Auth
alias Entendu.Links.Link
def find_or_create(%Auth{} = auth) do def find_or_create(%Auth{} = auth) do
{:ok, basic_info(auth)} {:ok, basic_info(auth)}

View File

@ -8,8 +8,6 @@ defmodule EntenduWeb.AuthController do
plug Ueberauth plug Ueberauth
alias Entendu.UserFromAuth alias Entendu.UserFromAuth
alias EntenduWeb.LinkView
alias Entendu.EncryptedLink
def delete(conn, _params) do def delete(conn, _params) do
conn conn
@ -27,7 +25,7 @@ defmodule EntenduWeb.AuthController do
def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do def callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
link = get_session(conn, :intended_link) link = get_session(conn, :intended_link)
with %{id: link_id, recipient: recipient} <- link, with %{id: link_id} <- link,
{:ok, user} <- UserFromAuth.find_or_create(auth) do {:ok, user} <- UserFromAuth.find_or_create(auth) do
# TODO: send over encrypted data that the frontend can decrypt # TODO: send over encrypted data that the frontend can decrypt

View File

@ -9,8 +9,6 @@ defmodule EntenduWeb.LinkController do
alias Entendu.Links alias Entendu.Links
alias Links.Link alias Links.Link
alias EntenduWeb.FallbackController alias EntenduWeb.FallbackController
alias Entendu.EncryptedLink
alias Entendu.UserFromAuth
alias EntenduWeb.Plugs.AuthorizeLink alias EntenduWeb.Plugs.AuthorizeLink
plug AuthorizeLink when action in [:text, :file] plug AuthorizeLink when action in [:text, :file]
@ -18,7 +16,8 @@ defmodule EntenduWeb.LinkController do
action_fallback(FallbackController) action_fallback(FallbackController)
def just_page(conn, _params) do def just_page(conn, _params) do
render(conn, "just.html") conn
|> render("just.html")
end end
def just(conn, params) do def just(conn, params) do
@ -46,7 +45,7 @@ defmodule EntenduWeb.LinkController do
end end
def auth_page(conn, %{"id" => link_id}) do def auth_page(conn, %{"id" => link_id}) do
with %Link{id: id, service: service, recipient: recipient} = link <- Links.get_link(link_id) do with %Link{id: id, service: service, recipient: recipient} <- Links.get_link(link_id) do
conn conn
|> put_session(:intended_link, %{id: id, service: service, recipient: recipient}) |> put_session(:intended_link, %{id: id, service: service, recipient: recipient})
|> render("auth.html", %{intended_link: %{service: service, recipient: recipient}}) |> render("auth.html", %{intended_link: %{service: service, recipient: recipient}})

View File

@ -7,7 +7,6 @@ defmodule EntenduWeb.PageController do
def index(conn, _params) do def index(conn, _params) do
conn conn
|> clear_session()
|> render("index.html") |> render("index.html")
end end

View File

@ -2,11 +2,9 @@ defmodule EntenduWeb.Plugs.AuthorizeLink do
import Plug.Conn import Plug.Conn
use EntenduWeb, :controller use EntenduWeb, :controller
alias Entendu.Repo
alias Entendu.UserFromAuth alias Entendu.UserFromAuth
alias Entendu.Links alias Entendu.Links
alias Entendu.Links.Link alias Entendu.Links.Link
alias EntenduWeb.FallbackController
alias EntenduWeb.ErrorView alias EntenduWeb.ErrorView
def init(_params) do def init(_params) do
@ -23,7 +21,7 @@ defmodule EntenduWeb.Plugs.AuthorizeLink do
if !user do if !user do
conn conn
|> put_status(403) |> put_status(403)
|> put_view(EntenduWeb.ErrorView) |> put_view(ErrorView)
|> render("error_code.json", message: "Unauthorized", code: 403) |> render("error_code.json", message: "Unauthorized", code: 403)
|> halt |> halt
else else
@ -35,21 +33,21 @@ defmodule EntenduWeb.Plugs.AuthorizeLink do
nil -> nil ->
conn conn
|> put_status(404) |> put_status(404)
|> put_view(EntenduWeb.ErrorView) |> put_view(ErrorView)
|> render("error_code.json", message: "Link could not be found", code: 404) |> render("error_code.json", message: "Link could not be found", code: 404)
|> halt |> halt
false -> false ->
conn conn
|> put_status(403) |> put_status(403)
|> put_view(EntenduWeb.ErrorView) |> put_view(ErrorView)
|> render("error_code.json", message: "Unauthorized", code: 403) |> render("error_code.json", message: "Unauthorized", code: 403)
|> halt |> halt
{:error, reason} -> {:error, reason} ->
conn conn
|> put_status(422) |> put_status(422)
|> put_view(EntenduWeb.ErrorView) |> put_view(ErrorView)
|> render("error_code.json", message: reason, code: 422) |> render("error_code.json", message: reason, code: 422)
|> halt |> halt
end end

View File

@ -36,7 +36,7 @@ defmodule Entendu.EncryptedLink do
# end # end
# Override the storage directory: # Override the storage directory:
def storage_dir(version, {_file, scope}) do def storage_dir(_version, {_file, scope}) do
"priv/uploads/links/#{scope.id}" "priv/uploads/links/#{scope.id}"
end end