Store Last.fm API key with encrypted secret

This commit is contained in:
Claudio Ortolina
2025-05-06 15:18:14 +01:00
parent d5b29b20bb
commit 95f71519d3
12 changed files with 87 additions and 9 deletions
@@ -1,18 +1,18 @@
defmodule MusicLibraryWeb.LastFmController do
use MusicLibraryWeb, :controller
def callback(conn, %{"token" => token}) do
case LastFm.get_session(token) do
{:ok, session} ->
conn
|> put_session(:last_fm_user, session.name)
|> put_session(:last_fm_key, session.key)
|> put_flash(:info, "Successfully authenticated with Last.fm.")
|> redirect(to: ~p"/")
alias MusicLibrary.Secrets
def callback(conn, %{"token" => token}) do
with {:ok, session} <- LastFm.get_session(token),
{:ok, _secret} <- Secrets.store("last_fm_key", session.key) do
conn
|> put_flash(:info, gettext("Successfully connected your Last.fm account"))
|> redirect(to: ~p"/")
else
{:error, reason} ->
conn
|> put_flash(:error, "Failed to authenticate with Last.fm: #{reason}")
|> put_flash(:error, "Failed to connect your Last.fm account: #{reason}")
|> redirect(to: ~p"/")
end
end