Update User Account callable function example
The following is a walkthrough of creating the Update User Account function example
Last updated
The following is a walkthrough of creating the Update User Account function example
Last updated
Users need to be able to update their accounts with a Github URL.
Login
as any user
Navigate
to the user account view
/account
Observe
view includes the following:
Update Github URL: <input>
Button to update the user's Github URL
Account
template updates to include new design
Account
component update to interact with the state
Account
state management updated to interact with API
onUpdateAccount
HTTPS callable function to update the /users/{{uid}}
document with new Github URL property
In the apps\full-stack-typescript-api\src\functions
folder, create the following:
Update
apps\full-stack-typescript-api\src\functions\account\index.ts
to be:
The new function receives a data
payload of type User
and merges the new data to the users document in our database.
Update
apps\full-stack-typescript-api\src\main.ts
to include the new function.
The main.ts
file is our primary entry point for our functions and needs to be updated so that our new function is included when the project is built.
Run the following command to build the functions application:
nx build full-stack-typescript-api
Run the following command to deploy new and updated functions:
firebase deploy --only functions
Now that we've created a secure method for interacting with the database, we need to update the frontend application to integrate with the new function.
Update
libs\features\account\src\lib\+state\account.actions.ts
to include the new actions:
updateAccount
updateAccountFailure
updateAccountSuccess
Update
libs\features\account\src\lib\+state\account.reducer.ts
to include:
Update
libs\features\account\src\lib\+state\account.facade.ts
to include:
Update
libs\features\account\src\lib\+state\account.effects.ts
to include:
Update
libs\services\account\src\lib\account.service.ts
to include:
Update
libs\features\account\src\lib\account.module.ts
to include the FormsModule
:
Update
libs\features\account\src\lib\account.component.ts
to include:
Update
libs\features\account\src\lib\account.component.html
to include:
There is now a secure way for users to update their account information with the database. The onUpdateAccount
function and Account
state accepts a User
payload which can include all of the attributes of User
.
The AccountComponent
can be improved to enable updating of all User
properties.
For this update, we will be creating an that allows users to update their account information directly from the application.
Additional types of functions can be reviewed here: