Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions web/lib/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { renderHook } from "@testing-library/react";

// Capture what useGoogleSignIn hands to Enoki's createAuthorizationURL.
const createAuthorizationURL = vi.fn(
(_input: { provider: string; extraParams?: { scope?: string[] } }) =>

Check warning on line 6 in web/lib/__tests__/auth.test.ts

View workflow job for this annotation

GitHub Actions / web

'_input' is defined but never used
Promise.resolve("https://accounts.google.com/o/oauth2/v2/auth?stub"),
);

vi.mock("@mysten/enoki/react", () => ({
useEnokiFlow: () => ({ createAuthorizationURL, logout: vi.fn() }),
useZkLogin: () => ({ address: null }),
}));
vi.mock("@mysten/dapp-kit-react", () => ({
useDAppKit: () => ({ disconnectWallet: vi.fn() }),
}));

import { useGoogleSignIn } from "../auth";

describe("useGoogleSignIn", () => {
beforeEach(() => createAuthorizationURL.mockClear());

// Regression for #96: Enoki defaults the scope to just "openid", and Google
// only emits `email`/`email_verified` claims when the `email` scope is asked
// for. Without it, /api/email/bind-google rejects with "Google email not
// verified". This pins the call site so the scope can't be dropped again.
it("requests the Google `email` scope", async () => {
const { result } = renderHook(() => useGoogleSignIn());
await result.current();
expect(createAuthorizationURL).toHaveBeenCalledTimes(1);
const arg = createAuthorizationURL.mock.calls[0][0];
expect(arg.provider).toBe("google");
expect(arg.extraParams?.scope).toContain("email");
});
});
7 changes: 7 additions & 0 deletions web/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export function useGoogleSignIn() {
clientId: GOOGLE_CLIENT_ID,
redirectUrl: authUrl.toString(),
network: ENOKI_NETWORK,
// Ask for the `email` scope so Google puts `email` + `email_verified`
// in the id_token. Enoki defaults to "openid" only; without this the
// token has no email claim and /api/email/bind-google rejects it with
// "Google email not verified" (#96). Scope doesn't affect the zkLogin
// address (derived from iss/aud/sub), so existing Google users are
// unaffected; `email` is a non-sensitive scope (no Google re-review).
extraParams: { scope: ["email"] },
});
window.location.href = url;
},
Expand Down
Loading