CurrentUser
CurrentUser
and CurrentServerUser
CurrentUser
and CurrentServerUser
provide functionalities like getting user profile, updating user information, send email verification, etc. CurrentServerUser
is a subclass of CurrentUser
and provides some additional functionalities like deleting users and server only metadata.
CurrentUser
Object
You can call useUser()
or stackServerApp.getUser()
to get the CurrentUser
object.
Attributes
id
(string): The user ID. This is the unique identifier of the user.displayName
(string | null): The display name of the user. Can be changed by the user.primaryEmail
(string | null): The primary email of the user. Note: this is not unique.primaryEmailVerified
(boolean): Whether the primary email is verified.profileImageUrl
(string | null): The profile image URL of the user.signedUpAt
(Date): The Date when the user signed up.emailAuthEnabled
(boolean): Whether the user has an email authentication method (magic link or password).hasPassword
(boolean): Whether the user has a password set.oauthProviders
(string[]): The list of OAuth provider ID s the user has connected.clientMetadata
(object): The JSON metadata that is visible on the client side. Note that this should not contain information that should be kept private on the server side.
Methods
update
This method can update the user’s profile information. Here is an example of how to update the user’s display name and set the client metadata.
signOut
This will sign out the user and clear the session.
Example:
sendEmailVerification
This will send an email verification link to the user’s primary email. It will return an error object (not throw an error) if the email is already verified. If successful, it will return undefined.
Example:
updatePassword
This will update the user’s password. It will return an error object (not throw an error) if the passwords mismatch or if the new password does not meet the requirements. If successful, it will return undefined.
Example:
CurrentServerUser
If you call getUser()
on a StackServerApp
, you will get the CurrentServerUser
object. It contains all the fields and methods of CurrentUser
, but also has some additional data.
Attributes
serverMetadata
: The JSON metadata that is visible on the server side. This contains information that should be kept private on the server side. Do not share this with the client.
Methods
delete
This will delete the user. Use it with caution as it is irreversible.
Example: