get-convex / convex-demos

Demo apps built on Convex.
https://docs.convex.dev/
171 stars 25 forks source link

UserIdentity.tokenIdentifier vs UserIdentity.subject in storeUser function #17

Closed leodevbro closed 1 year ago

leodevbro commented 1 year ago

Here: https://docs.convex.dev/auth/database-auth

The docs recommend using identity.tokenIdentifier to store the external auth id into our DB.

But it looks like this:

console.log(identity.tokenIdentifier);
logs this:
'https://normal-quagga-15.clerk.accounts.dev|user_2UqFb5XFIur7dYbfl7GuCGoUuRH'

Is the left side really needed?

Why don't we do simply this?

console.log(identity.subject);
logs this:
'user_2UqFb5XFIur7dYbfl7GuCGoUuRH'

I think the user_2UqFb5XFIur7dYbfl7GuCGoUuRH is totally unique and enough, right?

xixixao commented 1 year ago

If you're using only one provider, you can use subject. The left part in tokenIdentifier is needed to distinguish keys from two different providers, which might issue the same key:

Provider A, Key X
Provider B, Key X