|
| 1 | +import { getSSRSession } from '../sessionUtils' |
| 2 | +import { TryRefreshComponent } from './tryRefreshClientComponent' |
| 3 | +import styles from '../page.module.css' |
| 4 | +import { redirect } from 'next/navigation' |
| 5 | +import Image from 'next/image' |
| 6 | +import { CelebrateIcon, SeparatorLine } from '../../assets/images' |
| 7 | +import { CallAPIButton } from './callApiButton' |
| 8 | +import { LinksComponent } from './linksComponent' |
| 9 | +import { SessionAuthForNextJS } from './sessionAuthForNextJS' |
| 10 | + |
| 11 | +export async function HomePage() { |
| 12 | + const { session, hasToken, hasInvalidClaims } = await getSSRSession() |
| 13 | + |
| 14 | + if (!session) { |
| 15 | + if (!hasToken) { |
| 16 | + /** |
| 17 | + * This means that the user is not logged in. If you want to display some other UI in this |
| 18 | + * case, you can do so here. |
| 19 | + */ |
| 20 | + return redirect('/auth') |
| 21 | + } |
| 22 | + |
| 23 | + if (hasInvalidClaims) { |
| 24 | + return <SessionAuthForNextJS /> |
| 25 | + } else { |
| 26 | + return <TryRefreshComponent /> |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <SessionAuthForNextJS> |
| 32 | + <div className={styles.homeContainer}> |
| 33 | + <div className={styles.mainContainer}> |
| 34 | + <div |
| 35 | + className={`${styles.topBand} ${styles.successTitle} ${styles.bold500}`} |
| 36 | + > |
| 37 | + <Image |
| 38 | + src={CelebrateIcon} |
| 39 | + alt="Login successful" |
| 40 | + className={styles.successIcon} |
| 41 | + />{' '} |
| 42 | + Login successful |
| 43 | + </div> |
| 44 | + <div className={styles.innerContent}> |
| 45 | + <div>Your userID is:</div> |
| 46 | + <div className={`${styles.truncate} ${styles.userId}`}> |
| 47 | + {session.getUserId()} |
| 48 | + </div> |
| 49 | + <CallAPIButton /> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + <LinksComponent /> |
| 53 | + <Image |
| 54 | + className={styles.separatorLine} |
| 55 | + src={SeparatorLine} |
| 56 | + alt="separator" |
| 57 | + /> |
| 58 | + </div> |
| 59 | + </SessionAuthForNextJS> |
| 60 | + ) |
| 61 | +} |
0 commit comments