MCPcopy
hub / github.com/nextauthjs/next-auth / Header

Function Header

apps/example-nextjs/components/header.tsx:8–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6// component that works on pages which support both client and server side
7// rendering, and avoids any flash incorrect content on initial page load.
8export default function Header() {
9 const { data: session, status } = useSession()
10 const loading = status === "loading"
11
12 return (
13 <header>
14 <noscript>
15 <style>{`.nojs-show { opacity: 1; top: 0; }`}</style>
16 </noscript>
17 <div className={styles.signedInStatus}>
18 <p
19 className={`nojs-show ${
20 !session && loading ? styles.loading : styles.loaded
21 }`}
22 >
23 {!session && (
24 <>
25 <span className={styles.notSignedInText}>
26 You are not signed in
27 </span>
28 <a
29 href={`/api/auth/signin`}
30 className={styles.buttonPrimary}
31 onClick={(e) => {
32 e.preventDefault()
33 signIn()
34 }}
35 >
36 Sign in
37 </a>
38 </>
39 )}
40 {session?.user && (
41 <>
42 {session.user.image && (
43 <span
44 style={{ backgroundImage: `url('${session.user.image}')` }}
45 className={styles.avatar}
46 />
47 )}
48 <span className={styles.signedInText}>
49 <small>Signed in as</small>
50 <br />
51 <strong>{session.user.email ?? session.user.name}</strong>
52 </span>
53 <a
54 href={`/api/auth/signout`}
55 className={styles.button}
56 onClick={(e) => {
57 e.preventDefault()
58 signOut()
59 }}
60 >
61 Sign out
62 </a>
63 </>
64 )}
65 </p>

Callers

nothing calls this directly

Calls 3

useSessionFunction · 0.90
signInFunction · 0.90
signOutFunction · 0.90

Tested by

no test coverage detected