-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathpage-client.tsx
More file actions
320 lines (308 loc) · 13.1 KB
/
page-client.tsx
File metadata and controls
320 lines (308 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
"use client";
import Link from "next/link";
import { useParams, useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
import { AlertCircle } from "lucide-react";
import { SSOLogin } from "@/ee/features/security/sso";
import { signInWithPasskey } from "@teamhanko/passkeys-next-auth-provider/client";
import { signIn } from "next-auth/react";
import { toast } from "sonner";
import { z } from "zod";
import { cn } from "@/lib/utils";
import { LastUsed, useLastUsed } from "@/components/hooks/useLastUsed";
import Google from "@/components/shared/icons/google";
import LinkedIn from "@/components/shared/icons/linkedin";
import Passkey from "@/components/shared/icons/passkey";
import { LogoCloud } from "@/components/shared/logo-cloud";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export default function Login() {
const { next } = useParams as { next?: string };
const router = useRouter();
const searchParams = useSearchParams();
const authError = searchParams?.get("error");
const isSSORequired = authError === "require-saml-sso";
const [lastUsed, setLastUsed] = useLastUsed();
const authMethods = ["google", "email", "linkedin", "passkey"] as const;
type AuthMethod = (typeof authMethods)[number];
const [clickedMethod, setClickedMethod] = useState<AuthMethod | undefined>(
undefined,
);
const [email, setEmail] = useState<string>("");
const [emailButtonText, setEmailButtonText] = useState<string>(
"Continue with Email",
);
const emailSchema = z
.string()
.trim()
.toLowerCase()
.min(3, { message: "Please enter a valid email." })
.email({ message: "Please enter a valid email." });
const emailValidation = emailSchema.safeParse(email);
return (
<div className="flex h-screen w-full flex-wrap">
{/* Left part */}
<div className="flex w-full justify-center bg-gray-50 md:w-[55%] lg:w-[55%]">
<div
className="absolute inset-x-0 top-10 -z-10 flex transform-gpu justify-center overflow-hidden blur-3xl"
aria-hidden="true"
></div>
<div className="z-10 mx-5 mt-0 h-fit w-full max-w-md overflow-hidden rounded-lg sm:mx-0 sm:mt-[calc(0.5vh)] md:mt-[calc(1vh)]">
<div className="items-left flex flex-col space-y-3 px-4 py-6 pt-5 sm:px-12 sm:pt-6">
<Link href="https://www.papermark.com" target="_blank">
<img
src="/_static/papermark-logo.svg"
alt="Papermark Logo"
className="mb-24 h-7 w-auto self-start sm:mb-20"
/>
</Link>
<div className="flex items-center gap-4 pb-1">
<img
src="/_static/security-icons/soc2-dark-new3.png?v=2"
alt="SOC2 Compliant"
className="h-14 w-auto object-contain opacity-80"
/>
<img
src="/_static/security-icons/GDPR.svg"
alt="GDPR Compliant"
className="h-10 w-auto object-contain opacity-80"
/>
<img
src="/_static/security-icons/HIPAA.svg"
alt="HIPAA Compliant"
className="h-10 w-auto object-contain opacity-80"
/>
<img
src="/_static/security-icons/CCPA.svg"
alt="CCPA Compliant"
className="h-10 w-auto object-contain opacity-80"
/>
</div>
<p className="flex items-center gap-1.5 text-xs text-gray-600">
<span className="text-orange-400">★★★★★</span>
<span>trusted by 55,000+ companies to secure deals</span>
</p>
<Link href="/">
<span className="text-balance text-3xl font-semibold text-gray-900">
Welcome to Papermark
</span>
</Link>
<h3 className="text-balance text-sm text-gray-800">
Share documents. Not attachments.
</h3>
</div>
{isSSORequired && (
<div className="mx-4 mb-2 flex items-start gap-3 rounded-lg border border-orange-200 bg-orange-50 px-4 py-3 sm:mx-12">
<AlertCircle className="mt-0.5 h-5 w-5 flex-shrink-0 text-orange-600" />
<div>
<p className="text-sm font-medium text-orange-900">
Your organization requires SSO login
</p>
<p className="mt-1 text-sm text-orange-700">
Please use the <strong>SAML SSO</strong> option below to sign
in with your company's identity provider.
</p>
</div>
</div>
)}
<form
className="flex flex-col gap-4 px-4 pt-4 sm:px-12"
onSubmit={(e) => {
e.preventDefault();
if (!emailValidation.success) {
toast.error(emailValidation.error.errors[0].message);
return;
}
setClickedMethod("email");
signIn("email", {
email: emailValidation.data,
redirect: false,
...(next && next.length > 0 ? { callbackUrl: next } : {}),
}).then((res) => {
if (res?.ok && !res?.error) {
setLastUsed("credentials");
// Store email in sessionStorage for the verification page
try {
sessionStorage.setItem(
"pendingVerificationEmail",
emailValidation.data,
);
} catch {
// sessionStorage not available, verification page will show email input
}
router.push("/auth/email");
} else {
setEmailButtonText("Error sending email - try again?");
toast.error("Error sending email - try again?");
setClickedMethod(undefined);
}
});
}}
>
<Label className="sr-only" htmlFor="email">
Email
</Label>
<Input
id="email"
placeholder="name@example.com"
type="email"
autoCapitalize="none"
autoComplete="email"
autoCorrect="off"
disabled={clickedMethod === "email"}
// pattern={patternSimpleEmailRegex}
value={email}
onChange={(e) => setEmail(e.target.value)}
className={cn(
"flex h-10 w-full rounded-md border-0 bg-background bg-white px-3 py-2 text-sm text-gray-900 ring-1 ring-gray-200 transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 dark:bg-white",
email.length > 0 && !emailValidation.success
? "ring-red-500"
: "ring-gray-200",
)}
/>
<div className="relative">
<Button
type="submit"
loading={clickedMethod === "email"}
disabled={!emailValidation.success || !!clickedMethod}
className={cn(
"focus:shadow-outline w-full transform rounded px-4 py-2 text-white transition-colors duration-300 ease-in-out focus:outline-none disabled:opacity-100",
"bg-black hover:bg-gray-900",
)}
>
{emailButtonText}
</Button>
{lastUsed === "credentials" && <LastUsed />}
</div>
</form>
<p className="py-4 text-center">or</p>
<div className="flex flex-col space-y-2 px-4 sm:px-12">
<div className="relative">
<Button
onClick={() => {
setClickedMethod("google");
setLastUsed("google");
signIn("google", {
...(next && next.length > 0 ? { callbackUrl: next } : {}),
}).then((res) => {
setClickedMethod(undefined);
});
}}
loading={clickedMethod === "google"}
disabled={clickedMethod && clickedMethod !== "google"}
className="flex w-full items-center justify-center space-x-2 border border-gray-300 bg-gray-100 font-normal text-gray-900 hover:bg-gray-200"
>
<Google className="h-5 w-5" />
<span>Continue with Google</span>
{clickedMethod !== "google" && lastUsed === "google" && (
<LastUsed />
)}
</Button>
</div>
<div className="relative">
<Button
onClick={() => {
setClickedMethod("linkedin");
setLastUsed("linkedin");
signIn("linkedin", {
...(next && next.length > 0 ? { callbackUrl: next } : {}),
}).then((res) => {
setClickedMethod(undefined);
});
}}
loading={clickedMethod === "linkedin"}
disabled={clickedMethod && clickedMethod !== "linkedin"}
className="flex w-full items-center justify-center space-x-2 border border-gray-300 bg-gray-100 font-normal text-gray-900 hover:bg-gray-200"
>
<LinkedIn />
<span>Continue with LinkedIn</span>
{clickedMethod !== "linkedin" && lastUsed === "linkedin" && (
<LastUsed />
)}
</Button>
</div>
<div className="relative">
<Button
onClick={() => {
setLastUsed("passkey");
setClickedMethod("passkey");
signInWithPasskey({
tenantId: process.env.NEXT_PUBLIC_HANKO_TENANT_ID as string,
}).then(() => {
setClickedMethod(undefined);
});
}}
variant="outline"
loading={clickedMethod === "passkey"}
disabled={clickedMethod && clickedMethod !== "passkey"}
className="flex w-full items-center justify-center space-x-2 border border-gray-300 bg-gray-100 font-normal text-gray-900 hover:bg-gray-200 hover:text-gray-900"
>
<Passkey className="h-4 w-4" />
<span>Continue with a passkey</span>
{lastUsed === "passkey" && <LastUsed />}
</Button>
</div>
<div className="relative">
<SSOLogin autoExpand={isSSORequired} />
</div>
</div>
<p className="mt-10 w-full max-w-md px-4 text-xs text-muted-foreground sm:px-12">
By continuing, you agree to Papermark's{" "}
<a
href={`${process.env.NEXT_PUBLIC_MARKETING_URL || "https://www.papermark.com"}/terms`}
target="_blank"
rel="noopener noreferrer"
className="underline"
>
Terms of Service
</a>{" "}
and{" "}
<a
href={`${process.env.NEXT_PUBLIC_MARKETING_URL || "https://www.papermark.com"}/privacy`}
target="_blank"
rel="noopener noreferrer"
className="underline"
>
Privacy Policy
</a>
.
</p>
</div>
</div>
<div className="relative hidden w-full justify-center overflow-hidden bg-white md:flex md:w-[45%] lg:w-[45%]">
<div className="flex h-full w-full flex-col items-center justify-center px-4 py-10">
<div className="flex w-full max-w-xl flex-col items-center">
<div className="mb-5 w-full max-w-md">
<img
className="h-auto w-full rounded-2xl object-cover shadow-lg"
src="/_static/testimonials/backtrace.jpeg"
alt="Backtrace Capital"
/>
</div>
<div className="w-full max-w-3xl text-center">
<blockquote className="font-semibold leading-8 text-gray-900 sm:text-xl sm:leading-9">
<p>
"We raised €50M Fund with Papermark Data Rooms.
<br />
Secure, branded, and incredibly easy to use."
</p>
</blockquote>
<figcaption className="mt-4">
<div className="text-balance font-medium text-gray-900">
Michael Münnix
</div>
<div className="text-balance font-light text-gray-500">
Partner, Backtrace Capital
</div>
</figcaption>
</div>
</div>
<div className="mt-20 flex w-full max-w-md flex-col items-center">
<LogoCloud />
</div>
</div>
</div>
</div>
);
}