volatiletech / authboss

The boss of http auth.
MIT License
3.85k stars 207 forks source link

Database comes up empty. #260

Closed siredwin closed 4 years ago

siredwin commented 4 years ago

I cannot show logged-in username or confirm users because my database shows up empty.
I got it to populate only once but I could not re-create that again. The database is just a list of users. How do I accomplish this? Below is my storer that uses Mongo

// NewMemStorer constructor
func NewMemStorer() MemStorer {
    //seed
    user := User{ID:                 1,
        Name:               "Rick",
        Password:           "$2a$10$XtW/BrS5HeYIuOCXYe8DFuInetDMdaarMUJEOg/VA/JAIDgw3l4aG", // pass = 1234
        Email:              "rick@councilofricks.com",
        Confirmed:          true,
        SMSSeedPhoneNumber: "(777)-123-4567",
    }
    //////////////////////////////////////////////////
    memstore := MemStorer{
        Users: []User{user},
        //Users: map[string]User{"rick@councilofricks.com": user},
        Tokens: make(map[string][]string),
    }
    fmt.Println("memostoore users : ",  memstore.Users)
    //return memstore
    //////////////////////////////////////////////////////////////
    backend :=New()
    err := backend.Connect()
    if err != nil {
        fmt.Println("err at backend: ", err)
    }
    /////////////////////////////////////////////////
    err = backend.Ping()
    fmt.Println("ping err : ", err)
    ////////////////////////////////////////////////////
    err = backend.Insertmongo(user.Email, user.ConfirmSelector,user.RecoverSelector, user, memstore.Tokens,)
    if err != nil{
        fmt.Println("save err:", err)
    }
    ///////////////////////////////////////////////////////////////////////////////

    myuser, err := backend.FindResult(user.Email)
    if err != nil{
        fmt.Println("find oauth load err :", err)
        //return nil, authboss.ErrUserNotFound
    }
    fmt.Println("result ::", myuser)
    memstore.Users =  append(memstore.Users, *myuser)
    fmt.Println("memstore.Users ::", memstore.Users)

    return memstore
}