-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(share): return to video after signing in from denied share page (#2192) #2287
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { isValidElement, type ReactElement } from "react"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { PolicyDeniedView } from "../../app/s/[videoId]/_components/PolicyDeniedView"; | ||
|
|
||
| describe("PolicyDeniedView", () => { | ||
| it("renders private video sign in link and button with next param", () => { | ||
| const videoId = "vid12345"; | ||
| const view = PolicyDeniedView({ videoId }); | ||
| expect(isValidElement(view)).toBe(true); | ||
|
|
||
| const children = (view as ReactElement<{ children: ReactElement[] }>).props | ||
| .children; | ||
| const titleElement = children[1]; | ||
| const buttonElement = children[3]; | ||
|
|
||
| expect(titleElement.props.children).toBe("This video is private"); | ||
| expect(buttonElement).toBeDefined(); | ||
|
|
||
| const linkChild = buttonElement.props.children; | ||
| expect(linkChild.props.href).toBe("/login?next=%2Fs%2Fvid12345"); | ||
| }); | ||
|
|
||
| it("renders email restriction login required with next param", () => { | ||
| const videoId = "restricted987"; | ||
| const view = PolicyDeniedView({ | ||
| videoId, | ||
| reason: "email_restriction_login_required", | ||
| }); | ||
| expect(isValidElement(view)).toBe(true); | ||
|
|
||
| const children = (view as ReactElement<{ children: ReactElement[] }>).props | ||
| .children; | ||
| const titleElement = children[1]; | ||
| const buttonElement = children[3]; | ||
|
|
||
| expect(titleElement.props.children).toBe("This video requires sign-in"); | ||
| expect(buttonElement).toBeDefined(); | ||
|
|
||
| const linkChild = buttonElement.props.children; | ||
| expect(linkChild.props.href).toBe("/login?next=%2Fs%2Frestricted987"); | ||
| }); | ||
|
|
||
| it("renders email restriction denied without sign in button", () => { | ||
| const videoId = "restricted987"; | ||
| const view = PolicyDeniedView({ | ||
| videoId, | ||
| reason: "email_restriction_denied", | ||
| }); | ||
| expect(isValidElement(view)).toBe(true); | ||
|
|
||
| const children = ( | ||
| view as ReactElement<{ children: (ReactElement | boolean)[] }> | ||
| ).props.children; | ||
| const titleElement = children[1] as ReactElement; | ||
| const buttonElement = children[3]; | ||
|
|
||
| expect(titleElement.props.children).toBe("Access restricted"); | ||
| expect(buttonElement).toBe(false); | ||
| }); | ||
|
|
||
| it("falls back to /login when videoId is not provided", () => { | ||
| const view = PolicyDeniedView({}); | ||
| const children = (view as ReactElement<{ children: ReactElement[] }>).props | ||
| .children; | ||
| const buttonElement = children[3]; | ||
| expect(buttonElement).toBeDefined(); | ||
| const linkChild = buttonElement.props.children; | ||
| expect(linkChild.props.href).toBe("/login"); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { Button, Logo } from "@cap/ui"; | ||
| import Link from "next/link"; | ||
| import type React from "react"; | ||
|
|
||
| export interface PolicyDeniedViewProps { | ||
| videoId?: string; | ||
| reason?: string; | ||
| } | ||
|
|
||
| export function PolicyDeniedView({ videoId, reason }: PolicyDeniedViewProps) { | ||
| const loginHref = videoId | ||
| ? `/login?next=${encodeURIComponent(`/s/${videoId}`)}` | ||
| : "/login"; | ||
|
Comment on lines
+10
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A signed-in non-owner can reach this private-video view, but both sign-in links send them to Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/web/app/s/[videoId]/_components/PolicyDeniedView.tsx
Line: 10-13
Comment:
**Authenticated sign-in loops**
A signed-in non-owner can reach this private-video view, but both sign-in links send them to `/login?next=/s/{videoId}`. Because the login page detects the existing session and immediately returns them to the same denied page, this action creates a no-op redirect loop. This is non-blocking, but the sign-in option should only appear for anonymous viewers, or authenticated viewers should get an account-switch path.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| let title = "This video is private"; | ||
| let description: React.ReactNode = ( | ||
| <> | ||
| If you own this video, please{" "} | ||
| <Link href={loginHref} className="underline"> | ||
| sign in | ||
| </Link>{" "} | ||
| to manage sharing. | ||
| </> | ||
| ); | ||
| let showLoginButton = true; | ||
|
|
||
| if (reason === "email_restriction_login_required") { | ||
| title = "This video requires sign-in"; | ||
| description = ( | ||
| <> | ||
| The owner of this video has restricted access. Please{" "} | ||
| <Link href={loginHref} className="underline"> | ||
| sign in | ||
| </Link>{" "} | ||
| with an authorized email address to view. | ||
| </> | ||
| ); | ||
| } else if (reason === "email_restriction_denied") { | ||
| title = "Access restricted"; | ||
| description = | ||
| "Your email address does not meet the requirements set by the video owner."; | ||
| showLoginButton = false; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex flex-col justify-center items-center p-4 min-h-screen text-center"> | ||
| <Logo className="size-32" /> | ||
| <h1 className="mb-2 text-2xl font-semibold">{title}</h1> | ||
| <p className="text-gray-400">{description}</p> | ||
| {showLoginButton && ( | ||
| <Button asChild className="mt-6"> | ||
| <Link href={loginHref}>Sign in</Link> | ||
| </Button> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
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.
These tests inspect unrendered React children through fixed array positions. An unrelated markup reorder will break them, while they do not verify the actual anchor produced by
Button, RadixSlot, and Next.jsLink. This makes the tests brittle and gives less confidence in the rendered behavior; render the component to static markup and assert its visible text and anchor attributes instead. The same pattern also appears in the other tests in this file.Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!