wasp icon indicating copy to clipboard operation
wasp copied to clipboard

Improve our API for getting `providerData` for our auth providers

Open infomiho opened this issue 4 months ago • 1 comments

When users get the new AuthUser object, it contains a list of available auth identities. Each of those auth identities contains some extra fields in providerData (which fields are available depends on the auth provider).

There should a straightforward and type safe way to get the providerData for our users.

What we did ourselves

In the todoApp example app, we did the following:

export function getProviderData(user?: AuthUser) {
  if (!user) {
    return null
  }

  const emailIdentity = findUserIdentity(user, 'email')
  return emailIdentity && 'isEmailVerified' in emailIdentity.providerData
    ? emailIdentity.providerData
    : null
}

Good solution

I believe we can introduce a new API that would be called e.g. getProviderData<ProviderName> which can return the proper type based on the value of the generic param ProviderName. Or something similar, but ideally, users can use getProviderData and get a typed object.

infomiho avatar Feb 26 '24 21:02 infomiho

Related issue: https://github.com/wasp-lang/wasp/issues/1800 .

Martinsos avatar Mar 01 '24 08:03 Martinsos