mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
fix(steam): say why a Steam sign-in failed
The callback returns with the outcome in the query, since the sign-in happens on Steam's site, but nothing read it. A refused sign-in, an unreachable Steam or a flow that did not start here all returned the user to an unchanged section with no explanation. The reason is now shown in the snackbar, through the string the typed link already used, and both query parameters are dropped so a reload cannot repeat it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NH5s4gb7QNE7xa4pRUsBzx
This commit is contained in:
@@ -23,8 +23,11 @@ vi.mock("@/services/api/user", () => ({
|
||||
vi.mock("@/composables/useSnackbar", () => ({ useSnackbar: () => snackbar }));
|
||||
vi.mock("@/composables/useConfirm", () => ({ useConfirm: () => confirm }));
|
||||
vi.mock("@/composables/useSocketEvent", () => ({ useSocketEvent: vi.fn() }));
|
||||
const routerReplace = vi.fn();
|
||||
let routeQuery: Record<string, string> = {};
|
||||
vi.mock("vue-router", () => ({
|
||||
useRoute: () => ({ fullPath: "/settings/user/1" }),
|
||||
useRoute: () => ({ fullPath: "/settings/user/1", query: routeQuery }),
|
||||
useRouter: () => ({ replace: routerReplace }),
|
||||
}));
|
||||
|
||||
function mountSection() {
|
||||
@@ -51,12 +54,34 @@ function mountSection() {
|
||||
describe("SteamLibrarySection", () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("location", { ...window.location, assign });
|
||||
routeQuery = {};
|
||||
vi.mocked(userApi.fetchSteamLibrary).mockResolvedValue({
|
||||
data: [220, 400],
|
||||
} as never);
|
||||
vi.mocked(userApi.syncSteamLibrary).mockResolvedValue({} as never);
|
||||
});
|
||||
|
||||
it("reports a sign-in Steam refused and clears it from the url", async () => {
|
||||
storeAuth().setCurrentUser(userFixture({ id: 1 }));
|
||||
routeQuery = { steam_error: "Steam could not confirm the sign-in" };
|
||||
|
||||
mountSection();
|
||||
await flushPromises();
|
||||
|
||||
expect(snackbar.error).toHaveBeenCalledOnce();
|
||||
expect(routerReplace).toHaveBeenCalledWith({ query: {} });
|
||||
});
|
||||
|
||||
it("says nothing when no sign-in just happened", async () => {
|
||||
storeAuth().setCurrentUser(userFixture({ id: 1 }));
|
||||
|
||||
mountSection();
|
||||
await flushPromises();
|
||||
|
||||
expect(snackbar.error).not.toHaveBeenCalled();
|
||||
expect(routerReplace).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("hands the browser to Steam to sign in", async () => {
|
||||
storeAuth().setCurrentUser(userFixture({ id: 1 }));
|
||||
vi.mocked(userApi.startSteamLogin).mockResolvedValue({
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
// SteamLibrarySection: links a RomM account to a Steam account and imports
|
||||
// the games it owns. The import runs as a task whose completion arrives as a
|
||||
// notification, which also refreshes the owned count shown here.
|
||||
import { computed, ref } from "vue";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute } from "vue-router";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import SettingsSection from "@/components/Settings/SettingsSection.vue";
|
||||
import { useConfirm } from "@/composables/useConfirm";
|
||||
import { useSnackbar } from "@/composables/useSnackbar";
|
||||
@@ -18,6 +18,7 @@ defineOptions({ inheritAttrs: false });
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const auth = storeAuth();
|
||||
const steamLibrary = useSteamLibrary();
|
||||
const snackbar = useSnackbar();
|
||||
@@ -32,6 +33,23 @@ const personaName = computed(
|
||||
() => auth.user?.steam_persona_name || auth.user?.steam_id || "",
|
||||
);
|
||||
|
||||
// The sign-in happens on Steam's site, so its outcome comes back in the query
|
||||
// rather than in a reply this component awaited.
|
||||
onMounted(() => {
|
||||
const failure = route.query.steam_error;
|
||||
if (typeof failure === "string" && failure) {
|
||||
snackbar.error(t("settings.steam-link-failed", { error: failure }), {
|
||||
icon: "mdi-close-circle",
|
||||
});
|
||||
}
|
||||
if ("steam_error" in route.query || "steam" in route.query) {
|
||||
const query = { ...route.query };
|
||||
delete query.steam_error;
|
||||
delete query.steam;
|
||||
void router.replace({ query });
|
||||
}
|
||||
});
|
||||
|
||||
// Steam signs the user in on its own site, then returns to `next`, so this
|
||||
// hands the browser over rather than awaiting a reply.
|
||||
async function link() {
|
||||
|
||||
Reference in New Issue
Block a user