Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6 from mainawycliffe/fix-login-issue
Browse files Browse the repository at this point in the history
Fix Unable To Login When Token Is Empty
  • Loading branch information
mainawycliffe authored Apr 17, 2020
2 parents cb339e3 + 2ef6209 commit 8b7af32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
var loginCmd = &cobra.Command{
Use: "login",
Short: "Log kamanda into firebase",
Long: `This allows Kamanda to administer your Firebase Project.
You can use --no-localhost flag if you are on environment without a browser.`,
Example: `kamanda login`,
Run: func(cmd *cobra.Command, args []string) {
if viper.IsSet(configs.FirebaseRefreshTokenViperConfigKey) {
if utils.IsUserLoggedIn() {
email := viper.GetString(configs.FirebaseLoggedInUserEmailViperConfigKey)
utils.StdOutSuccess(os.Stdout, "Already logged in as %s\n", email)
os.Exit(1)
Expand Down
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ import (
"time"

"github.com/logrusorgru/aurora"
"github.com/mainawycliffe/kamanda/configs"
"github.com/spf13/viper"
"gopkg.in/yaml.v2"
)

// IsUserLoggedIn checks whether a firebase refresh token is set in the configurations
func IsUserLoggedIn() bool {
if viper.IsSet(configs.FirebaseRefreshTokenViperConfigKey) && viper.GetString(configs.FirebaseLoggedInUserEmailViperConfigKey) != "" {
// todo: probably check the format of the token to ensure its correct
return true
}
return false
}

// ParseStringToActualValue takes a string and converts the string the actual
// type of the string i.e. "true" => true
func ParseStringToActualValueType(input string) interface{} {
Expand Down

0 comments on commit 8b7af32

Please sign in to comment.