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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,12 @@ type (
|
|||||||
}
|
}
|
||||||
User struct {
|
User struct {
|
||||||
Pubkey string
|
Pubkey string
|
||||||
|
Msats int64
|
||||||
LastSeen time.Time
|
LastSeen time.Time
|
||||||
}
|
}
|
||||||
Session struct {
|
Session struct {
|
||||||
Pubkey string
|
Pubkey string
|
||||||
|
Msats int64
|
||||||
SessionId string
|
SessionId string
|
||||||
}
|
}
|
||||||
Market struct {
|
Market struct {
|
||||||
|
@ -25,6 +25,6 @@ func HandleCheckSession(sc context.ServerContext) echo.HandlerFunc {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return c.JSON(http.StatusInternalServerError, 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}
|
s = &db.Session{SessionId: cookie.Value}
|
||||||
if err = sc.Db.FetchSession(s); err == nil {
|
if err = sc.Db.FetchSession(s); err == nil {
|
||||||
// session found
|
// 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 {
|
if err = sc.Db.UpdateUser(u); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { computed, ref } from 'vue'
|
|||||||
|
|
||||||
export const useSession = defineStore('session', () => {
|
export const useSession = defineStore('session', () => {
|
||||||
const pubkey = ref(null)
|
const pubkey = ref(null)
|
||||||
|
const msats = ref(0)
|
||||||
const initialized = ref(false)
|
const initialized = ref(false)
|
||||||
const isAuthenticated = computed(() => initialized.value ? !!pubkey.value : undefined)
|
const isAuthenticated = computed(() => initialized.value ? !!pubkey.value : undefined)
|
||||||
|
|
||||||
@ -17,6 +18,9 @@ export const useSession = defineStore('session', () => {
|
|||||||
pubkey.value = body.pubkey
|
pubkey.value = body.pubkey
|
||||||
console.log('authenticated as', body.pubkey)
|
console.log('authenticated as', body.pubkey)
|
||||||
} else console.log('unauthenticated')
|
} else console.log('unauthenticated')
|
||||||
|
if (body.msats) {
|
||||||
|
msats.value = body.msats
|
||||||
|
}
|
||||||
initialized.value = true
|
initialized.value = true
|
||||||
return body
|
return body
|
||||||
}).catch(err => {
|
}).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