Skip to content

Open source CapCut alternative.

TypeScript

feat(site): native Google/Apple ID-token sign-in and bearer sessions for the iOS app

David Le2d7ca63e7f1d
diff --git a/site/src/lib/auth.ts b/site/src/lib/auth.ts
index 59afa65d..ad66404e 100644
--- a/site/src/lib/auth.ts
+++ b/site/src/lib/auth.ts
@@ -1,5 +1,6 @@
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
+import { bearer } from "better-auth/plugins";
import { DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";
import { provisionSignupGrants } from "@/lib/onboarding/signup-grants";
@@ -13,6 +14,14 @@ import { prisma } from "@/lib/prisma";
// derives it from the localhost request.
const baseURL = process.env.VERCEL ? DONKEYCUT_CANONICAL : undefined;
+// The iOS app signs in natively and exchanges the provider's ID token for a
+// session at /api/auth/sign-in/social. ID tokens are verified against these
+// native OAuth clients alongside the web client. The Google iOS client id is
+// deployment-specific, so it rides the environment (GOOGLE_IOS_CLIENT_ID)
+// with the other Google OAuth values.
+const IOS_APP_BUNDLE_ID = "com.donkeycut.donkeycut";
+const APPLE_SERVICES_ID = "com.donkeycut.signin";
+
export const auth = betterAuth({
baseURL,
secret: process.env.BETTER_AUTH_SECRET,
@@ -47,11 +56,26 @@ export const auth = betterAuth({
},
socialProviders: {
google: {
- clientId: process.env.GOOGLE_CLIENT_ID ?? "",
+ // The first entry drives the web OAuth flow; the rest are accepted
+ // audiences for native ID-token sign-in.
+ clientId: [
+ process.env.GOOGLE_CLIENT_ID,
+ process.env.GOOGLE_IOS_CLIENT_ID,
+ ].filter((id): id is string => !!id),
clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
// Always show Google's account chooser: without this, a browser with one
// signed-in Google session silently reuses the last-used account.
prompt: "select_account",
},
+ apple: {
+ clientId: APPLE_SERVICES_ID,
+ clientSecret: process.env.APPLE_CLIENT_SECRET ?? "",
+ // Native Sign in with Apple mints tokens whose audience is the app's
+ // bundle id.
+ appBundleIdentifier: IOS_APP_BUNDLE_ID,
+ },
},
+ // The iOS app holds its session as a bearer token (`set-auth-token`
+ // response header, then `Authorization: Bearer` on every call).
+ plugins: [bearer()],
});