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

Commit

Permalink
Add a UI for Viewing Firebase Auth Users [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Mar 28, 2020
1 parent aeb2ce7 commit 50d91c1
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 56 deletions.
47 changes: 44 additions & 3 deletions cmd/listUsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package cmd

import (
"context"
"fmt"
"os"

"github.com/gdamore/tcell"
"github.com/mainawycliffe/kamanda/firebase/auth"
"github.com/mainawycliffe/kamanda/utils"
"github.com/rivo/tview"
"github.com/spf13/cobra"
)

Expand All @@ -25,9 +28,47 @@ var listUsersCmd = &cobra.Command{
utils.StdOutError(os.Stderr, "Error! %s", err.Error())
os.Exit(1)
}
// @todo: do something with the response i.e save to file or list them
utils.StdOutSuccess(os.Stdout, "Next Page Token %s", getUsers.NextPageToken)
utils.StdOutSuccess(os.Stdout, "Number of Users: %d", len(getUsers.Users))
if getUsers.NextPageToken != "" {
utils.StdOutSuccess(os.Stdout, "Next Page Token %s", getUsers.NextPageToken)
}
// @todo: set the width of the table to 100%
app := tview.NewApplication()
table := tview.NewTable()
tableHeaderColumnNames := []string{"#", "UID", "Email", "Name", "Phone Number"}
for index, value := range tableHeaderColumnNames {
tableCell := tview.NewTableCell(value).SetTextColor(tcell.ColorWhite).SetBackgroundColor(tcell.ColorBlue)
table.SetCell(0, index, tableCell)
}
for i, v := range getUsers.Users {
isEmailVerified := ""
if !v.EmailVerified {
isEmailVerified = "(Not Verified)"
}
table.SetCell(i+1, 0, tview.NewTableCell(fmt.Sprintf("%d", i+1))).SetSelectable(false, false)
table.SetCell(i+1, 1, tview.NewTableCell(v.UID)).SetSelectable(true, false)
table.SetCell(i+1, 2, tview.NewTableCell(fmt.Sprintf("%s (%s)", v.Email, isEmailVerified))).SetSelectable(true, false)
table.SetCell(i+1, 3, tview.NewTableCell(v.DisplayName)).SetSelectable(true, false)
table.SetCell(i+1, 4, tview.NewTableCell(v.PhoneNumber)).SetSelectable(true, false)
}
table.Select(1, 0).SetFixed(1, 1).SetDoneFunc(func(key tcell.Key) {
// exit when the following keys ae pressed
if key == tcell.KeyEscape || key == tcell.KeyCtrlW {
app.Stop()
}
if key == tcell.KeyEnter {
table.SetSelectable(true, true)
}
}).SetSelectedFunc(func(row int, column int) {
uid := table.GetCell(row, 1).Text
fmt.Printf("%s\n", uid)
// @todo: fetch from firebase the user details

})
// @todo add pagination to get more request
if err := app.SetRoot(table, true).Run(); err != nil {
utils.StdOutError(os.Stderr, "Error! %s", err.Error())
os.Exit(1)
}
},
}

Expand Down
27 changes: 12 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,30 @@ module github.com/mainawycliffe/kamanda
go 1.12

require (
cloud.google.com/go v0.54.0 // indirect
cloud.google.com/go/firestore v1.1.1 // indirect
cloud.google.com/go/firestore v1.2.0 // indirect
firebase.google.com/go v3.12.0+incompatible
github.com/bitfield/script v0.14.1
github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/cpuguy83/go-md2man v1.0.10 // indirect
github.com/bitfield/script v0.14.2
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-chi/chi v4.0.3+incompatible
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/gdamore/tcell v1.3.0
github.com/go-chi/chi v4.0.4+incompatible
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/rivo/tview v0.0.0-20200219210816-cd38d7432498
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v0.0.6
github.com/spf13/cobra v0.0.7
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
golang.org/x/exp v0.0.0-20200228211341-fcea875c7e85 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/tools v0.0.0-20200313205530-4303120df7d8 // indirect
golang.org/x/sys v0.0.0-20200327173247-9dae0f8f5775 // indirect
golang.org/x/tools v0.0.0-20200328031815-3db5fc6bac03 // indirect
google.golang.org/api v0.20.0
google.golang.org/genproto v0.0.0-20200313141609-30c55424f95d // indirect
google.golang.org/grpc v1.28.0 // indirect
gopkg.in/ini.v1 v1.54.0 // indirect
google.golang.org/genproto v0.0.0-20200326112834-f447254575fd // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/yaml.v2 v2.2.8
)
Loading

0 comments on commit 50d91c1

Please sign in to comment.