This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Command to Verify or Unverify Users Email
This command allows you to set the status of the email address for one or more users account on Firebase Auth. Closes #19
- Loading branch information
1 parent
fda70f9
commit ee91f38
Showing
2 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/mainawycliffe/kamanda/firebase/auth" | ||
"github.com/mainawycliffe/kamanda/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var verifyEmailCmd = &cobra.Command{ | ||
Use: "isEmailVerified", | ||
Aliases: []string{"is-email-verified"}, | ||
Short: "Manually verify or un-verify a users email address.", | ||
Example: "kamanda users set isEmailVerified --status=false [UID] [UID]", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
emailVerifiedStatus, _ := cmd.Flags().GetBool("status") | ||
hasError := false | ||
for _, v := range args { | ||
updatePassword := &auth.FirebaseUser{ | ||
ShouldUpdateEmailVerified: true, | ||
EmailVerified: emailVerifiedStatus, | ||
} | ||
user, err := auth.UpdateFirebaseUser(context.Background(), v, updatePassword) | ||
if err != nil { | ||
hasError = true | ||
utils.StdOutError(os.Stderr, "Error updating user %s email verified status\n", v) | ||
continue | ||
} | ||
utils.StdOutSuccess(os.Stdout, "Email verified status for user %s [%s] has been set to %s\n", user.UID, user.Email, emailVerifiedStatus) | ||
} | ||
if hasError { | ||
os.Exit(1) | ||
} | ||
os.Exit(0) | ||
}, | ||
} | ||
|
||
func init() { | ||
setCmd.AddCommand(verifyEmailCmd) | ||
verifyEmailCmd.Flags().BoolP("status", "s", false, "The email verified value to set to") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters