feat: support updating user's display name
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
linkWithCredential,
|
||||
AuthCredential,
|
||||
UserCredential,
|
||||
updateProfile,
|
||||
} from "firebase/auth"
|
||||
import {
|
||||
onSnapshot,
|
||||
@@ -295,6 +296,28 @@ export async function setProviderInfo(id: string, token: string) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user's display name
|
||||
*
|
||||
* @param name - The new display name
|
||||
*/
|
||||
export async function setDisplayName(name: string) {
|
||||
if (!currentUser$.value) throw new Error("No user has logged in")
|
||||
|
||||
const us = {
|
||||
displayName: name,
|
||||
}
|
||||
|
||||
try {
|
||||
await updateProfile(currentUser$.value, us).catch((e) =>
|
||||
console.error("error updating", us, e)
|
||||
)
|
||||
} catch (e) {
|
||||
console.error("error updating", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
export function getGithubCredentialFromResult(result: UserCredential) {
|
||||
return GithubAuthProvider.credentialFromResult(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user