Add msats to session
This commit is contained in:
parent
49cacb266c
commit
28546962f3
@ -6,7 +6,8 @@ func (db *DB) CreateSession(s *Session) error {
|
||||
}
|
||||
|
||||
func (db *DB) FetchSession(s *Session) error {
|
||||
err := db.QueryRow("SELECT pubkey FROM sessions WHERE session_id = $1", s.SessionId).Scan(&s.Pubkey)
|
||||
query := "SELECT u.pubkey, u.msats FROM sessions s LEFT JOIN users u ON u.pubkey = s.pubkey WHERE session_id = $1"
|
||||
err := db.QueryRow(query, s.SessionId).Scan(&s.Pubkey, &s.Msats)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,12 @@ type (
|
||||
}
|
||||
User struct {
|
||||
Pubkey string
|
||||
Msats int64
|
||||
LastSeen time.Time
|
||||
}
|
||||
Session struct {
|
||||
Pubkey string
|
||||
Msats int64
|
||||
SessionId string
|
||||
}
|
||||
Market struct {
|
||||
|
@ -25,6 +25,6 @@ func HandleCheckSession(sc context.ServerContext) echo.HandlerFunc {
|
||||
} else if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, nil)
|
||||
}
|
||||
return c.JSON(http.StatusOK, map[string]string{"pubkey": s.Pubkey})
|
||||
return c.JSON(http.StatusOK, map[string]any{"pubkey": s.Pubkey, "msats": s.Msats})
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func Session(sc context.ServerContext) echo.MiddlewareFunc {
|
||||
s = &db.Session{SessionId: cookie.Value}
|
||||
if err = sc.Db.FetchSession(s); err == nil {
|
||||
// session found
|
||||
u = &db.User{Pubkey: s.Pubkey, LastSeen: time.Now()}
|
||||
u = &db.User{Pubkey: s.Pubkey, Msats: s.Msats, LastSeen: time.Now()}
|
||||
if err = sc.Db.UpdateUser(u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import { computed, ref } from 'vue'
|
||||
|
||||
export const useSession = defineStore('session', () => {
|
||||
const pubkey = ref(null)
|
||||
const msats = ref(0)
|
||||
const initialized = ref(false)
|
||||
const isAuthenticated = computed(() => initialized.value ? !!pubkey.value : undefined)
|
||||
|
||||
@ -17,6 +18,9 @@ export const useSession = defineStore('session', () => {
|
||||
pubkey.value = body.pubkey
|
||||
console.log('authenticated as', body.pubkey)
|
||||
} else console.log('unauthenticated')
|
||||
if (body.msats) {
|
||||
msats.value = body.msats
|
||||
}
|
||||
initialized.value = true
|
||||
return body
|
||||
}).catch(err => {
|
||||
@ -40,5 +44,5 @@ export const useSession = defineStore('session', () => {
|
||||
})
|
||||
}
|
||||
|
||||
return { pubkey, isAuthenticated, initialized, checkSession, login, logout }
|
||||
return { pubkey, isAuthenticated, initialized, msats, checkSession, login, logout }
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user