Sign in with Apple
POST /v1/auth/apple verifies the ID token from Sign in with Apple JS against Apple's keys, the Services IDs in APPLE_CLIENT_IDS and Apple's issuer, then logs in like Google: the linked identity, else the user with the same verified address, else a new user (invitations and referrals as for Google). The Google verifier became a shared ID token verifier. Apple gives the name only at the first sign-in; the page sends it along (family name first). The login page shows Apple's white button under Google's when it is configured; the privacy pages say what Apple passes on, including the relay addresses. The deploy compose's MAIL_FROM default is noreply@ like production (the sender registered for Apple's e-mail relay). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -57,7 +57,10 @@ export default async function PrivacyPage() {
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Google-fiókod neve, e-mail-címe és azonosítója (belépéskor a Google adja át)</td>
|
||||
<td>
|
||||
Google- vagy Apple-fiókod neve, e-mail-címe és azonosítója (belépéskor a Google, illetve az Apple adja
|
||||
át)
|
||||
</td>
|
||||
<td>Fiókod létrehozása, belépés, kapcsolattartás</td>
|
||||
<td>Szerződés teljesítése (GDPR 6. cikk (1) b)</td>
|
||||
</tr>
|
||||
@@ -168,6 +171,13 @@ export default async function PrivacyPage() {
|
||||
</a>{" "}
|
||||
szabályzatnak, beleértve a „Limited Use” (korlátozott felhasználás) követelményeit.
|
||||
</p>
|
||||
<p>
|
||||
<strong>Belépés Apple-fiókkal:</strong> ha az „Apple-bejelentkezést” választod, az Apple a fiókod egyedi
|
||||
azonosítóját és az e-mail-címedet adja át, az első belépéskor a nevedet is. Ha az e-mail-címedet elrejted,
|
||||
egy Apple-továbbítócímet kapunk (<code>…@privaterelay.appleid.com</code>): az erre küldött leveleinket az Apple
|
||||
továbbítja hozzád. Ezeket ugyanarra és ugyanúgy használjuk, mint a Google-adatokat. A hozzáférést az Apple ID
|
||||
beállításaidban vonhatod vissza (Bejelentkezés és biztonság › Bejelentkezés az Apple-lel).
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
"use client";
|
||||
|
||||
import Script from "next/script";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { Waitlist } from "@/components/Waitlist";
|
||||
import { ApiError, api, errorText } from "@/lib/api";
|
||||
|
||||
/** The part of Sign in with Apple JS (appleid.auth.js) we use. */
|
||||
interface AppleSignInResponse {
|
||||
authorization: { id_token: string; code: string; state?: string };
|
||||
/** Only at the first sign-in of this Apple ID on the site. */
|
||||
user?: { email?: string; name?: { firstName?: string; lastName?: string } };
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
AppleID?: {
|
||||
auth: {
|
||||
init(options: { clientId: string; scope: string; redirectURI: string; state?: string; usePopup: boolean }): void;
|
||||
signIn(): Promise<AppleSignInResponse>;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** Apple's logo (Sign in with Apple guidelines: the logo left of the label). */
|
||||
function AppleMark() {
|
||||
return (
|
||||
<svg width="18" height="20" viewBox="0 0 17 20" aria-hidden="true" fill="currentColor">
|
||||
<path d="M13.77 10.62c-.02-2.2 1.8-3.26 1.88-3.31-1.03-1.5-2.62-1.7-3.18-1.73-1.35-.14-2.64.8-3.33.8-.69 0-1.74-.78-2.86-.76-1.47.02-2.83.86-3.59 2.17-1.53 2.65-.39 6.57 1.1 8.72.73 1.05 1.6 2.23 2.73 2.19 1.1-.04 1.51-.71 2.84-.71 1.32 0 1.7.71 2.86.69 1.18-.02 1.93-1.07 2.65-2.12.84-1.22 1.18-2.4 1.2-2.46-.03-.01-2.29-.88-2.3-3.48zM11.6 4.17c.6-.73 1.01-1.75.9-2.76-.87.04-1.92.58-2.54 1.31-.56.65-1.05 1.69-.92 2.68.97.08 1.96-.49 2.56-1.23z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/** The e-mail address inside Apple's ID token (only for the waitlist form; the backend verifies the token). */
|
||||
function tokenEmail(idToken: string): string {
|
||||
try {
|
||||
const part = idToken.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
||||
const bytes = Uint8Array.from(atob(part), (c) => c.charCodeAt(0));
|
||||
const email = JSON.parse(new TextDecoder().decode(bytes)).email;
|
||||
return typeof email === "string" ? email : "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "Continue with Apple": Apple's sign-in opens in a popup and returns an ID
|
||||
* token, which the backend verifies. Apple gives the name only at the first
|
||||
* sign-in, so it is sent along then (Hungarian order: family name first).
|
||||
*/
|
||||
export function AppleLogin({
|
||||
clientId,
|
||||
target,
|
||||
inviteToken = null,
|
||||
}: {
|
||||
clientId: string;
|
||||
target: string;
|
||||
inviteToken?: string | null;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [ready, setReady] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [uninvited, setUninvited] = useState<string | null>(null);
|
||||
|
||||
function loaded() {
|
||||
window.AppleID?.auth.init({
|
||||
clientId,
|
||||
scope: "name email",
|
||||
redirectURI: `${window.location.origin}/belepes`,
|
||||
usePopup: true,
|
||||
});
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
async function signIn() {
|
||||
const apple = window.AppleID;
|
||||
if (!apple) return;
|
||||
setError(null);
|
||||
setUninvited(null);
|
||||
let response: AppleSignInResponse;
|
||||
try {
|
||||
response = await apple.auth.signIn();
|
||||
} catch (e) {
|
||||
// Closing the popup is not an error worth showing.
|
||||
const code = (e as { error?: string } | null)?.error;
|
||||
if (code !== "popup_closed_by_user" && code !== "user_cancelled_authorize") {
|
||||
setError("Az Apple-belépés nem sikerült. Próbáld újra.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
const name = [response.user?.name?.lastName, response.user?.name?.firstName].filter(Boolean).join(" ") || null;
|
||||
try {
|
||||
let referral: string | null = null;
|
||||
try {
|
||||
referral = localStorage.getItem("sf_ref");
|
||||
} catch {
|
||||
// storage blocked
|
||||
}
|
||||
await api("/auth/apple", {
|
||||
body: { id_token: response.authorization.id_token, name, invite_token: inviteToken, referral },
|
||||
});
|
||||
try {
|
||||
localStorage.removeItem("sf_ref");
|
||||
} catch {
|
||||
// storage blocked
|
||||
}
|
||||
router.replace(target);
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === "not_invited") setUninvited(tokenEmail(response.authorization.id_token));
|
||||
else setError(errorText(e));
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field">
|
||||
<Script
|
||||
src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/hu_HU/appleid.auth.js"
|
||||
strategy="afterInteractive"
|
||||
onReady={loaded}
|
||||
onError={() => setError("Nem sikerült betölteni az Apple-belépést. Ellenőrizd a hálózatot vagy a reklámblokkolót.")}
|
||||
/>
|
||||
<button type="button" className="btn-social btn-apple" onClick={signIn} disabled={!ready || busy}>
|
||||
<span className="btn-social-icon">
|
||||
<AppleMark />
|
||||
</span>
|
||||
{busy ? "Belépés…" : "Folytatás Apple-fiókkal"}
|
||||
</button>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{uninvited !== null && (
|
||||
<>
|
||||
<p className="msg msg-error" role="alert">
|
||||
{inviteToken
|
||||
? "Ez a meghívó már nem érvényes, és ehhez az Apple-fiókhoz sem tartozik másik."
|
||||
: "A Sorsfonalak jelenleg meghívásos, és ehhez az Apple-fiókhoz nem tartozik meghívó. Ha kaptál meghívót, nyisd meg a levélben kapott linket, vagy lépj be azzal a fiókkal, amelynek a címére a meghívó szólt."}
|
||||
</p>
|
||||
<Waitlist email={uninvited.endsWith("@privaterelay.appleid.com") ? "" : uninvited} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { BACKEND_URL, getMe } from "@/lib/server";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { InvitationLanding, PublicConfig } from "@/lib/types";
|
||||
|
||||
import { AppleLogin } from "./AppleLogin";
|
||||
import { GoogleLogin } from "./GoogleLogin";
|
||||
|
||||
export const metadata: Metadata = { title: "Belépés" };
|
||||
@@ -43,7 +44,7 @@ const CLOSED: Record<string, string> = {
|
||||
};
|
||||
|
||||
/** The invitation the visitor came with: who sent it and what they wrote. */
|
||||
function InvitationCard({ invitation }: { invitation: InvitationLanding | null }) {
|
||||
function InvitationCard({ invitation, apple }: { invitation: InvitationLanding | null; apple: boolean }) {
|
||||
if (!invitation) {
|
||||
return (
|
||||
<p className="msg msg-error" role="alert">
|
||||
@@ -66,7 +67,7 @@ function InvitationCard({ invitation }: { invitation: InvitationLanding | null }
|
||||
</p>
|
||||
{invitation.message && <blockquote className="invite-quote">{invitation.message}</blockquote>}
|
||||
<p className="hint" style={{ margin: 0 }}>
|
||||
Bármelyik Google-fiókoddal elfogadhatod. Érvényes: {formatDate(invitation.expires_at).replace(/\.$/, "")}-ig.
|
||||
Bármelyik {apple ? "Google- vagy Apple-fiókoddal" : "Google-fiókoddal"} elfogadhatod. Érvényes: {formatDate(invitation.expires_at).replace(/\.$/, "")}-ig.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
@@ -83,6 +84,8 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
|
||||
inviteToken ? loadInvitation(inviteToken) : Promise.resolve(null),
|
||||
]);
|
||||
const clientId = config?.google_login.enabled ? config.google_login.client_id : null;
|
||||
const appleId = config?.apple_login?.enabled ? config.apple_login.client_id : null;
|
||||
const pendingInvite = invitation?.status === "pending" ? inviteToken : null;
|
||||
const inviteOnly = config?.signup_mode === "invite";
|
||||
|
||||
return (
|
||||
@@ -107,17 +110,16 @@ export default async function LoginPage({ searchParams }: { searchParams: Promis
|
||||
<h1 style={{ fontSize: 44 }}>{rawToken ? "Meghívó" : "Belépés"}</h1>
|
||||
<p className="muted">{rawToken ? "Lépj be, és már kezdheted is." : "Üdv újra! Lépj be a fiókodba."}</p>
|
||||
</div>
|
||||
{rawToken && <InvitationCard invitation={inviteToken ? invitation : null} />}
|
||||
{rawToken && <InvitationCard invitation={inviteToken ? invitation : null} apple={appleId !== null} />}
|
||||
{config === null ? (
|
||||
<p className="msg msg-error" role="alert">
|
||||
A szerver most nem érhető el. Próbáld újra egy kicsit később.
|
||||
</p>
|
||||
) : clientId ? (
|
||||
<GoogleLogin
|
||||
clientId={clientId}
|
||||
target={target}
|
||||
inviteToken={invitation?.status === "pending" ? inviteToken : null}
|
||||
/>
|
||||
<div className="field" style={{ gap: 12 }}>
|
||||
<GoogleLogin clientId={clientId} target={target} inviteToken={pendingInvite} />
|
||||
{appleId && <AppleLogin clientId={appleId} target={target} inviteToken={pendingInvite} />}
|
||||
</div>
|
||||
) : (
|
||||
<p className="msg msg-error" role="alert">
|
||||
A Google-belépés még nincs beállítva (a backend <code>GOOGLE_CLIENT_IDS</code> változója üres).
|
||||
|
||||
@@ -210,6 +210,11 @@ td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.social-login:hover .btn-social { border-color: #5a6790; background: rgba(255, 255, 255, 0.03); }
|
||||
.social-login:focus-within .btn-social { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.social-login[data-ready="false"] .btn-social { opacity: 0.6; }
|
||||
/* Sign in with Apple: Apple's white button style. */
|
||||
.btn-apple { background: #fff; border-color: #fff; color: #000; cursor: pointer; }
|
||||
.btn-apple:hover:not(:disabled) { background: #e8e8ed; border-color: #e8e8ed; }
|
||||
.btn-apple:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
|
||||
.btn-apple:disabled { opacity: 0.6; cursor: default; }
|
||||
.gsi-overlay {
|
||||
position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
|
||||
opacity: 0.001; overflow: hidden; cursor: pointer;
|
||||
|
||||
@@ -12,7 +12,7 @@ export const metadata: Metadata = {
|
||||
|
||||
const DATA: [string, string, string][] = [
|
||||
[
|
||||
"Your Google account's name, e-mail address and ID (passed on by Google when you sign in)",
|
||||
"Your Google or Apple account's name, e-mail address and ID (passed on by Google or Apple when you sign in)",
|
||||
"Creating your account, signing you in, contacting you",
|
||||
"Performance of a contract (GDPR Art. 6(1)(b))",
|
||||
],
|
||||
@@ -168,6 +168,13 @@ export default async function PrivacyPolicyPage() {
|
||||
</a>
|
||||
, including the Limited Use requirements.
|
||||
</p>
|
||||
<p>
|
||||
<strong>Signing in with Apple:</strong> if you choose “Sign in with Apple”, Apple passes us your account's
|
||||
unique ID and your e-mail address, and your name the first time. If you hide your address, we get an Apple
|
||||
relay address (<code>…@privaterelay.appleid.com</code>) and Apple forwards our e-mails to you. We use these
|
||||
for the same purposes and in the same way as the Google data. You can revoke access in your Apple ID settings
|
||||
(Sign-In and Security › Sign in with Apple).
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
Reference in New Issue
Block a user