feat: support updating user's display name

This commit is contained in:
liyasthomas
2021-10-16 15:01:32 +05:30
parent 748318d44e
commit 9f0956556f
6 changed files with 92 additions and 55 deletions

View File

@@ -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)
}