#can i force a specific user id when i do auth

4 messages · Page 1 of 1 (latest)

mystic grail
#

sign in with apple

spiral sageBOT
#

Hi @mystic grail. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the provided knowledge sources, Convex Auth does not support directly forcing a specific user ID when signing in with Apple (or any other provider) through its standard OAuth flow. The user ID is typically derived from the information provided by the authentication provider (in this case, Apple), such as the sub (subject) field in the Apple ID token, and is managed internally by Convex Auth.

When configuring the Apple provider, the user profile (including the user ID) is constructed from the data Apple returns after authentication. For example, the configuration in convex/auth.ts uses appleInfo.sub as the user ID:

Apple({
  profile: (appleInfo) => {
    const name = appleInfo.user
      ? `${appleInfo.user.name.firstName} ${appleInfo.user.name.lastName}`
      : undefined;
    return {
      id: appleInfo.sub,
      name: name,
      email: appleInfo.email,
    };
  },
}),

This means the user ID is set based on Apple’s unique identifier for the user, not an arbitrary value you provide yourself Provider configuration in auth.ts.

If you are implementing a custom credentials provider (e.g., for native Apple sign-in in React Native/Expo), you can technically control the value passed as the account ID when creating or retrieving the user, but this should still correspond to a unique, verifiable identifier from Apple (such as the email or Apple user ID from the token). For example:

#
const createdAccount = await createAccount(ctx, {
  provider: 'native-apple',
  account: { id: validatedTokenData.email },
  profile: {
    email: validatedTokenData.email,
    name: 'User',
    emailVerificationTime: Date.now(),
  },
  shouldLinkViaEmail: true,
});

Here, the id is set to the email, but this is still based on the data returned by Apple, not an arbitrary value Discord support thread: Convex Auth with Expo and Native Apple and Google Sign In.

In summary:
You cannot arbitrarily force a user ID during Apple sign-in; Convex Auth expects the user ID to be derived from the provider’s data for security and consistency. If you need to associate additional IDs or metadata, you should store them in your user profile or a related table, not as the primary user ID.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: