Skip to content

Commit 3c06370

Browse files
committed
Extract SignInButton
1 parent 5c35977 commit 3c06370

File tree

2 files changed

+47
-36
lines changed

2 files changed

+47
-36
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use client"
2+
3+
import { signIn } from "next-auth/react"
4+
import { Button, Stack, Typography } from "@mui/material"
5+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
6+
import { faGithub, faMicrosoft } from "@fortawesome/free-brands-svg-icons"
7+
8+
interface SignInButtonProps {
9+
providerId: string
10+
}
11+
12+
export default function SignInButton({ providerId }: SignInButtonProps) {
13+
const providerIcon = providerId === "microsoft-entra-id" ? faMicrosoft : faGithub
14+
const providerName = providerId === "microsoft-entra-id" ? "Microsoft" : "GitHub"
15+
16+
return (
17+
<Button
18+
variant="outlined"
19+
onClick={() => signIn(providerId, { callbackUrl: "/" })}
20+
>
21+
<Stack direction="row" alignItems="center" spacing={1} padding={1}>
22+
<FontAwesomeIcon icon={providerIcon} size="2xl" />
23+
<Typography variant="h6" sx={{ display: "flex" }}>
24+
Sign in with {providerName}
25+
</Typography>
26+
</Stack>
27+
</Button>
28+
)
29+
}

src/app/auth/signin/page.tsx

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import Image from "next/image"
2-
import { Box, Button, Stack, Typography } from "@mui/material"
3-
import { signIn } from "@/composition"
2+
import { Box, Stack, Typography } from "@mui/material"
43
import { env } from "@/common"
5-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
6-
import { faGithub, faMicrosoft } from "@fortawesome/free-brands-svg-icons"
74
import SignInTexts from "@/features/auth/view/SignInTexts"
85
import MessageLinkFooter from "@/common/ui/MessageLinkFooter"
6+
import SignInButton from "./SignInButton"
97

108
const SITE_NAME = env.getOrThrow("FRAMNA_DOCS_TITLE")
119
const HELP_URL = env.get("FRAMNA_DOCS_HELP_URL")
1210
const PROJECT_SOURCE_PROVIDER = env.get("PROJECT_SOURCE_PROVIDER") || "github"
1311

1412
// Force page to be rendered dynamically to ensure we read the correct values for the environment variables.
1513
export const dynamic = "force-dynamic"
16-
14+
1715
export default async function Page() {
16+
const isAzureDevOps = PROJECT_SOURCE_PROVIDER === "azure-devops"
17+
const providerId = isAzureDevOps ? "microsoft-entra-id" : "github"
18+
1819
return (
1920
<Box display="flex" height="100vh">
20-
<InfoColumn/>
21-
<SignInColumn/>
21+
<InfoColumn />
22+
<SignInColumn
23+
providerId={providerId}
24+
/>
2225
</Box>
2326
)
2427
}
@@ -37,7 +40,11 @@ const InfoColumn = () => {
3740
)
3841
}
3942

40-
const SignInColumn = () => {
43+
interface SignInColumnProps {
44+
providerId: string
45+
}
46+
47+
const SignInColumn = ({ providerId }: SignInColumnProps) => {
4148
const title = `Get started with ${SITE_NAME}`
4249
return (
4350
<Box
@@ -75,42 +82,17 @@ const SignInColumn = () => {
7582
}}>
7683
{title}
7784
</Typography>
78-
<SignInButton />
85+
<SignInButton providerId={providerId} />
7986
</Stack>
8087
</Box>
8188
{HELP_URL && (
8289
<Box sx={{ marginBottom: 2 }}>
83-
<MessageLinkFooter
90+
<MessageLinkFooter
8491
url={HELP_URL}
8592
content={`Learn more about ${SITE_NAME}`}
8693
/>
8794
</Box>
88-
)}
95+
)}
8996
</Box>
9097
)
9198
}
92-
93-
const SignInButton = () => {
94-
const isAzureDevOps = PROJECT_SOURCE_PROVIDER === "azure-devops"
95-
const providerId = isAzureDevOps ? "microsoft-entra-id" : "github"
96-
const providerName = isAzureDevOps ? "Microsoft" : "GitHub"
97-
const providerIcon = isAzureDevOps ? faMicrosoft : faGithub
98-
99-
return (
100-
<form
101-
action={async () => {
102-
"use server"
103-
await signIn(providerId, { redirectTo: "/" })
104-
}}
105-
>
106-
<Button variant="outlined" type="submit">
107-
<Stack direction="row" alignItems="center" spacing={1} padding={1}>
108-
<FontAwesomeIcon icon={providerIcon} size="2xl" />
109-
<Typography variant="h6" sx={{ display: "flex" }}>
110-
Sign in with {providerName}
111-
</Typography>
112-
</Stack>
113-
</Button>
114-
</form>
115-
)
116-
}

0 commit comments

Comments
 (0)