# Sign up and sign in with Google and Apple

Google and Apple ship off and switch on per project with their environment variables. Apple's client secret signs itself, social sign-ups get the same Organization and records as email sign-ups, and the app signs in natively with Apple on iOS.

- **New: social sign-in, off by default.** Better Auth registers Google when `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` are set, and Apple when all five `APPLE_*` variables are set; half a provider stays off and is logged once. Nothing is project-specific, and a fresh project shows no buttons. See [Social sign-in](/docs/features/auth#social-sign-in-google-and-apple). ([1e8a7f6](https://github.com/CarlosZiegler/template-cloudflare/commit/1e8a7f68dcbb3c589b55e62a2e787dcb2e3ee72a), [5c9d90b](https://github.com/CarlosZiegler/template-cloudflare/commit/5c9d90b8122496c07ac6ba521ab74186dcf59218))
- **Apple's client secret signs itself.** The server signs the ES256 JWT Apple requires from the `.p8` key with Web Crypto, valid 30 days, cached per isolate and renewed a day before it expires, so nobody rotates it. Checked on the built Worker in local workerd and in Node tests. `https://appleid.apple.com` is a trusted origin while Apple is on, for its form post callback. ([5c9d90b](https://github.com/CarlosZiegler/template-cloudflare/commit/5c9d90b8122496c07ac6ba521ab74186dcf59218))
- **The same account either way.** A Google or Apple sign-up goes through the same hooks as an email sign-up: personal Organization, owner membership, `user.created`, `org.created` and `auth.sign_in` audits, the Active Organization on the Session, and one welcome email. An integration test compares the three paths on a local Postgres. ([5c9d90b](https://github.com/CarlosZiegler/template-cloudflare/commit/5c9d90b8122496c07ac6ba521ab74186dcf59218))
- **Linking only by a verified address.** Google or Apple joins an existing User only when the provider vouches for the address and the User has verified it too. An unverified password account gets `account_not_linked` instead of being taken over, and a User with two-factor on gets no social Session (`TWO_FACTOR_REQUIRED`) because Better Auth's challenge covers credential sign-ins only. Apple's name, sent only on the first authorization, is kept; without one the address's local part stands in. See [Accounts and linking](/docs/features/auth#accounts-and-linking). ([5c9d90b](https://github.com/CarlosZiegler/template-cloudflare/commit/5c9d90b8122496c07ac6ba521ab74186dcf59218))
- **Clients show only what is on.** `appConfig.get` lists `auth.socialProviders` (names only, also in its fallback), and the web sign-in and sign-up pages render "Continue with Google / Apple" from it on the first paint, with each brand's mark, a spinner while the browser leaves and a message when the provider sends the person back with an error. ([cf2459e](https://github.com/CarlosZiegler/template-cloudflare/commit/cf2459e02089af9ffe8e0af0bde06ef6e9febeb7), [c71367e](https://github.com/CarlosZiegler/template-cloudflare/commit/c71367ea75a1ed965c527b7f60d234f263d47f89))
- **Mobile.** On iOS the app uses the native Sign in with Apple sheet and sends its identity token with a nonce: the server refuses an Apple token without one. Google goes through the Expo plugin's browser flow. App Store guideline 4.8 is in the button logic: on iOS Google shows only next to Apple. `expo-apple-authentication` and `expo-crypto` are native modules, so rebuild the development client. ([e8d4919](https://github.com/CarlosZiegler/template-cloudflare/commit/e8d4919eeb056be20b386f58bd5b366a77fd2299))
- **Setup.** `pnpm setup` offers both providers, reads the Apple key from its `.p8` file, refuses half a provider, and `--worker-secrets` publishes them as Worker secrets; `pnpm doctor` names missing variables. The auth guide has the Google Cloud and Apple Developer console steps. ([b1e05de](https://github.com/CarlosZiegler/template-cloudflare/commit/b1e05dec3577b4bd6a6c25e613ec1291c29bda2f), [2bc6da7](https://github.com/CarlosZiegler/template-cloudflare/commit/2bc6da7b2bb4935a76225a21c2cf7cb3c0c773b1))
