Implement login resolver (#15)

* add sign_up_method to users table

* add session store

* implement login resolver
This commit is contained in:
Lakhan Samani
2021-07-15 00:13:19 +05:30
committed by GitHub
parent 336fe10ca4
commit 27264c6e29
20 changed files with 874 additions and 884 deletions

View File

@@ -0,0 +1,43 @@
package session
import (
"context"
"log"
"github.com/go-redis/redis/v8"
)
type RedisStore struct {
ctx context.Context
store *redis.Client
}
func (c *RedisStore) AddToken(userId, token string) {
err := c.store.Set(c.ctx, "yauth_"+userId, token, 0).Err()
if err != nil {
log.Fatalln("Error saving redis token:", err)
}
}
func (c *RedisStore) DeleteToken(userId string) {
err := c.store.Del(c.ctx, "yauth_"+userId).Err()
if err != nil {
log.Fatalln("Error deleting redis token:", err)
}
}
func (c *RedisStore) ClearStore() {
err := c.store.Del(c.ctx, "yauth_*").Err()
if err != nil {
log.Fatalln("Error clearing redis store:", err)
}
}
func (c *RedisStore) GetToken(userId string) string {
token := ""
token, err := c.store.Get(c.ctx, "yauth_"+userId).Result()
if err != nil {
log.Println("Error getting token from redis store:", err)
}
return token
}