How-to Guides
Sign In with Apple
Authenticate users with Apple Sign In and access identity information
Sign In with Apple
Use the SDK's Auth module to sign in users with Apple. Apple sign-in returns a typed result with an identity object containing user-specific fields.
Prerequisites
- The starti.app SDK is installed and initialized
- Apple sign-in is configured for your app in the starti.app manager
Steps
Call signIn with the "apple" provider
const result = await startiapp.Auth.signIn("apple");Handle the Apple-specific result
When the provider is "apple", the SDK returns an AuthenticationResultApple with an identity object:
if (result.isSuccess) {
console.log("User ID:", result.identity.userId);
console.log("Email:", result.identity.email);
console.log("ID Token:", result.identity.idToken);
console.log("Name:", result.identity.name);
} else {
console.error("Sign in failed:", result.errorMessage);
}Apple only provides the user's name on the first sign-in. On subsequent
sign-ins, identity.name will be null. Store the name on your backend when you
first receive it.
Complete example
await startiapp.initialize();
async function loginWithApple() {
const result = await startiapp.Auth.signIn("apple");
if (!result.isSuccess) {
alert("Login failed: " + result.errorMessage);
return;
}
// Send the identity to your backend
await fetch("/api/auth/apple", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
userId: result.identity.userId,
email: result.identity.email,
name: result.identity.name,
idToken: result.identity.idToken,
authorizationCode: result.authorizationCode,
}),
});
}Apple identity fields
| Field | Type | Description |
|---|---|---|
userId | string | Apple's stable user identifier |
email | string | The user's email address |
name | string | null | Full name (only on first sign-in) |
idToken | string | A JWT you can verify server-side |