-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: UI polish, auth flow, and webkit compatibility #1556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ImLukeF
wants to merge
6
commits into
main
Choose a base branch
from
imlukef/ui-auth-webkit-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c89b13d
fix: improve auth flow, skill filters, and webkit compatibility
ImLukeF a93a6ef
test: mock auth actions in settings route
ImLukeF 15c555a
fix: remove stale skills toolbar props
ImLukeF e05883f
fix: address skills filter and webkit review feedback
ImLukeF 3f74917
test: avoid monaco lazy import in skill detail test
ImLukeF d96cddf
fix: recompute other skills category filter
ImLukeF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* @vitest-environment jsdom */ | ||
|
|
||
| import { fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { SignInButton } from "./SignInButton"; | ||
|
|
||
| const signInMock = vi.fn(); | ||
| const clearAuthErrorMock = vi.fn(); | ||
| const setAuthErrorMock = vi.fn(); | ||
| const getUserFacingAuthErrorMock = vi.fn(); | ||
|
|
||
| vi.mock("@convex-dev/auth/react", () => ({ | ||
| useAuthActions: () => ({ | ||
| signIn: signInMock, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("../lib/useAuthError", () => ({ | ||
| clearAuthError: () => clearAuthErrorMock(), | ||
| setAuthError: (message: string) => setAuthErrorMock(message), | ||
| })); | ||
|
|
||
| vi.mock("../lib/authErrorMessage", () => ({ | ||
| getUserFacingAuthError: (error: unknown, fallback: string) => | ||
| getUserFacingAuthErrorMock(error, fallback), | ||
| })); | ||
|
|
||
| describe("SignInButton", () => { | ||
| beforeEach(() => { | ||
| signInMock.mockReset(); | ||
| clearAuthErrorMock.mockReset(); | ||
| setAuthErrorMock.mockReset(); | ||
| getUserFacingAuthErrorMock.mockReset(); | ||
| getUserFacingAuthErrorMock.mockImplementation((_, fallback) => fallback); | ||
| window.history.replaceState(null, "", "/skills?q=test#top"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("starts GitHub sign-in with the current relative URL by default", async () => { | ||
| signInMock.mockResolvedValue({ signingIn: true }); | ||
|
|
||
| render(<SignInButton>Sign in with GitHub</SignInButton>); | ||
| fireEvent.click(screen.getByRole("button", { name: "Sign in with GitHub" })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(signInMock).toHaveBeenCalledWith("github", { | ||
| redirectTo: "/skills?q=test#top", | ||
| }); | ||
| }); | ||
| expect(clearAuthErrorMock).toHaveBeenCalledTimes(1); | ||
| expect(setAuthErrorMock).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("surfaces a generic error when sign-in resolves without redirecting", async () => { | ||
| signInMock.mockResolvedValue({ signingIn: false }); | ||
|
|
||
| render(<SignInButton>Sign in with GitHub</SignInButton>); | ||
| fireEvent.click(screen.getByRole("button", { name: "Sign in with GitHub" })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(setAuthErrorMock).toHaveBeenCalledWith("Sign in failed. Please try again."); | ||
| }); | ||
| }); | ||
|
|
||
| it("surfaces user-facing auth errors when sign-in rejects", async () => { | ||
| const failure = new Error("oauth failed"); | ||
| signInMock.mockRejectedValue(failure); | ||
| getUserFacingAuthErrorMock.mockReturnValue("GitHub auth unavailable"); | ||
|
|
||
| render(<SignInButton>Sign in with GitHub</SignInButton>); | ||
| fireEvent.click(screen.getByRole("button", { name: "Sign in with GitHub" })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(getUserFacingAuthErrorMock).toHaveBeenCalledWith( | ||
| failure, | ||
| "Sign in failed. Please try again.", | ||
| ); | ||
| expect(setAuthErrorMock).toHaveBeenCalledWith("GitHub auth unavailable"); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { useAuthActions } from "@convex-dev/auth/react"; | ||
| import type { ComponentProps } from "react"; | ||
| import { getUserFacingAuthError } from "../lib/authErrorMessage"; | ||
| import { clearAuthError, setAuthError } from "../lib/useAuthError"; | ||
| import { Button } from "./ui/button"; | ||
|
|
||
| type ButtonProps = ComponentProps<typeof Button>; | ||
|
|
||
| type SignInButtonProps = Omit<ButtonProps, "onClick" | "type"> & { | ||
| redirectTo?: string; | ||
| }; | ||
|
|
||
| export function SignInButton({ | ||
| redirectTo, | ||
| children = "Sign in with GitHub", | ||
| ...props | ||
| }: SignInButtonProps) { | ||
| const { signIn } = useAuthActions(); | ||
|
|
||
| return ( | ||
| <Button | ||
| type="button" | ||
| onClick={() => { | ||
| clearAuthError(); | ||
| const next = redirectTo ?? getCurrentRelativeUrl(); | ||
| void signIn("github", next ? { redirectTo: next } : undefined) | ||
| .then((result) => { | ||
| if (result?.signingIn === false) { | ||
| setAuthError("Sign in failed. Please try again."); | ||
| } | ||
| }) | ||
| .catch((error) => { | ||
| setAuthError( | ||
| getUserFacingAuthError(error, "Sign in failed. Please try again."), | ||
| ); | ||
| }); | ||
| }} | ||
| {...props} | ||
| > | ||
| {children} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| function getCurrentRelativeUrl() { | ||
| if (typeof window === "undefined") return "/"; | ||
| return `${window.location.pathname}${window.location.search}${window.location.hash}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| export type SkillCategory = { | ||
| slug: string; | ||
| label: string; | ||
| keywords: string[]; | ||
| }; | ||
|
|
||
| export const SKILL_CATEGORIES: SkillCategory[] = [ | ||
| { slug: "mcp-tools", label: "MCP Tools", keywords: ["mcp", "tool", "server"] }, | ||
| { slug: "prompts", label: "Prompts", keywords: ["prompt", "template", "system"] }, | ||
| { slug: "workflows", label: "Workflows", keywords: ["workflow", "pipeline", "chain"] }, | ||
| { slug: "dev-tools", label: "Dev Tools", keywords: ["dev", "debug", "lint", "test", "build"] }, | ||
| { slug: "data", label: "Data & APIs", keywords: ["api", "data", "fetch", "http", "rest", "graphql"] }, | ||
| { slug: "security", label: "Security", keywords: ["security", "scan", "auth", "encrypt"] }, | ||
| { slug: "automation", label: "Automation", keywords: ["auto", "cron", "schedule", "bot"] }, | ||
| { slug: "other", label: "Other", keywords: [] }, | ||
| ]; | ||
|
|
||
| export const ALL_CATEGORY_KEYWORDS = SKILL_CATEGORIES.flatMap((c) => c.keywords); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export function hasOwnProperty<K extends PropertyKey>( | ||
| value: unknown, | ||
| key: K, | ||
| ): value is Record<K, unknown> { | ||
| return typeof value === "object" && value !== null && Object.prototype.hasOwnProperty.call(value, key); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
responseis cast toPackageCatalogBrowseResponsewithout validating thatitemsis present/array-shaped. If the API ever returns an unexpected shape (orresultsexists but isn’t an array), this will returnundefinedfields and likely fail later. Consider usinghasOwnProperty(response, "items")+Array.isArray(...)(and validatingnextCursor) and throwing aPackageApiError(or a clear fallback) when the shape is unrecognized.