Files
OpenFrontIO/tests/HasLinkedAccount.test.ts
T
Josh Harris ff5eb78689 Login with Google — client UI (#4028) (#4279)
Resolves #4028 (client half — backend is openfrontio/infra#368, which
must be deployed first).

## Description:

Adds "Login with Google" to the client, alongside the existing Discord
login. Companion to the backend PR (openfrontio/infra#368).

- `Auth.ts` — `googleLogin()` (full-page redirect to
`/auth/login/google?redirect_uri=…`, mirrors `discordLogin()`).
- `ApiSchemas.ts` — `GoogleUserSchema` + optional `user.google` on
`UserMeResponseSchema`.
- `AccountModal.ts` — a "Login with Google" button (Google brand
guidelines: white surface, dark text, the multicolor "G" mark) in the
login options, and the logged-in view now renders a Google-authenticated
user's email (also added `google` to `isLinkedAccount()`).
- `en.json` — `main.login_google`.
- `resources/images/GoogleLogo.svg` — the Google "G" mark.

> **Draft.** Depends on infra#368 being deployed (the button hits the
live `/auth/login/google`).

## Please complete the following:

- [x] I have added screenshots for all UI updates <!-- TODO: add
screenshot of the Google button -->
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory <!-- no client
tests exist for AccountModal/Auth; verified via tsc --noEmit + eslint.
Backend behaviour is covered in infra#368 -->

## Please put your Discord username so you can be contacted if a bug or
regression is found:

jish
2026-06-19 11:47:40 +01:00

37 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { hasLinkedAccount } from "../src/client/Api";
import { UserMeResponse } from "../src/core/ApiSchemas";
// hasLinkedAccount gates the top bar, matchmaking, single-player, ranked, and
// the skins-page "not logged in" warning. A Google login sets user.google (no
// discord/email), so it must count as logged in — otherwise the UI shows
// "Sign in" despite a valid session (regression: Google users seen as logged
// out everywhere except the account modal).
function userWith(user: Record<string, unknown>): UserMeResponse {
return { user } as unknown as UserMeResponse;
}
describe("hasLinkedAccount", () => {
it("returns false when not logged in", () => {
expect(hasLinkedAccount(false)).toBe(false);
});
it("returns false when the user has no linked identity", () => {
expect(hasLinkedAccount(userWith({}))).toBe(false);
});
it("recognizes a Discord login", () => {
expect(hasLinkedAccount(userWith({ discord: { id: "1" } }))).toBe(true);
});
it("recognizes an email (magic-link) login", () => {
expect(hasLinkedAccount(userWith({ email: "a@example.com" }))).toBe(true);
});
it("recognizes a Google login", () => {
expect(
hasLinkedAccount(userWith({ google: { email: "a@example.com" } })),
).toBe(true);
});
});