File tree Expand file tree Collapse file tree 4 files changed +24
-71
lines changed
Expand file tree Collapse file tree 4 files changed +24
-71
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import { render , screen } from "@testing-library/react" ;
2- import { expect , test } from "vitest" ;
3- import Home from "@/app/(authed)/page" ;
4-
5- test ( "Home page renders welcome heading and link to catalog when user is logged in" , async ( ) => {
6- render ( await Home ( ) ) ;
7-
8- expect (
9- screen . getByRole ( "heading" , {
10- level : 1 ,
11- name : / W e l c o m e t o T o o l H i v e C l o u d U I / i,
12- } ) ,
13- ) . toBeDefined ( ) ;
14-
15- expect ( screen . getByText ( / Y o u a r e l o g g e d i n a s / i) ) . toBeDefined ( ) ;
16- expect ( screen . getByText ( / t e s t @ e x a m p l e .c o m / i) ) . toBeDefined ( ) ;
17-
18- const catalogLink = screen . getByRole ( "link" , { name : / G o t o C a t a l o g / i } ) ;
19- expect ( catalogLink ) . toBeDefined ( ) ;
20- expect ( catalogLink . getAttribute ( "href" ) ) . toBe ( "/catalog" ) ;
1+ import * as nextNavigation from "next/navigation" ;
2+ import { expect , test , vi } from "vitest" ;
3+ import Home from "@/app/page" ;
4+
5+ test ( "Home redirects to /catalog when user is logged in" , async ( ) => {
6+ const redirectSpy = vi . spyOn ( nextNavigation , "redirect" ) ;
7+ await Home ( ) ;
8+ expect ( redirectSpy ) . toHaveBeenCalledWith ( "/catalog" ) ;
219} ) ;
Original file line number Diff line number Diff line change 1+ import { headers } from "next/headers" ;
2+ import { redirect } from "next/navigation" ;
3+ import { auth } from "@/lib/auth/auth" ;
4+
5+ export default async function Home ( ) {
6+ const session = await auth . api . getSession ( {
7+ headers : await headers ( ) ,
8+ } ) ;
9+
10+ if ( ! session ) {
11+ redirect ( "/signin" ) ;
12+ }
13+
14+ // Authenticated: redirect straight to Catalog
15+ redirect ( "/catalog" ) ;
16+ }
You can’t perform that action at this time.
0 commit comments