Currently the authenticated User isn't exposed by the API directly but has to be retrieved separately using ext::auth::Identity. EdgeDB doesn't have the notion of a User, it knows only identities and a User is just another type that happens to be associated with an Identity.
There is a lot of flexibility in this approach as the User type can be defined by the application and carry any additional information. However, it is more intuitive and practical to have the User as the primary object exposed by auth. Most applications will want to associate a User with other types (like author of a Post).
Currently the User is created as a side-effect when the Identity is retrieved:
|
|
|
if (!user && token) { |
|
user = await client.query(` |
|
insert User { |
|
name := '', |
|
identity := global ext::auth::ClientTokenIdentity |
|
} |
|
`) |
|
} |
|
|
That doesn't feel right, especially if you want to collect other data (like name) as part of the signup process. It's more intuitive to create the User in the signup handler instead of merely a side-effect in the identity handler. The email and password fields can be used to create the identity and all other fields are assigned to the User.
It might be good to allow for customizing the User type etc. but for now, I'd just require that if auth is enabled, there has to be a type named User which has to have at least an identity field.
Just an idea so far. Let me know what you think!
Currently the authenticated User isn't exposed by the API directly but has to be retrieved separately using
ext::auth::Identity. EdgeDB doesn't have the notion of a User, it knows only identities and a User is just another type that happens to be associated with an Identity.There is a lot of flexibility in this approach as the User type can be defined by the application and carry any additional information. However, it is more intuitive and practical to have the User as the primary object exposed by auth. Most applications will want to associate a User with other types (like author of a Post).
Currently the User is created as a side-effect when the Identity is retrieved:
nuxt-edgedb/src/runtime/api/auth/identity.ts
Lines 15 to 24 in 37ac5c4
That doesn't feel right, especially if you want to collect other data (like name) as part of the signup process. It's more intuitive to create the User in the signup handler instead of merely a side-effect in the identity handler. The email and password fields can be used to create the identity and all other fields are assigned to the User.
It might be good to allow for customizing the User type etc. but for now, I'd just require that if auth is enabled, there has to be a type named
Userwhich has to have at least an identity field.Just an idea so far. Let me know what you think!