Skip to content

Commit 0c3816e

Browse files
committed
Backend: rename db.Authorize to db.AuthenticateBySessionKey.
1 parent 0282118 commit 0c3816e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

backend/db/session.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ func AuthenticateByCredentials(credentials Credentials) (int, error) {
4343
return userID, nil
4444
}
4545

46-
func Authorize(sessionKey string) error {
47-
query := `SELECT session_key FROM sessions WHERE session_key = ?`
48-
err := db.QueryRow(query, sessionKey).Scan(&sessionKey)
46+
func AuthenticateBySessionKey(sessionKey string) (int, error) {
47+
var userID int
48+
49+
query := `SELECT user_id FROM sessions WHERE session_key = ?`
50+
err := db.QueryRow(query, sessionKey).Scan(&userID)
4951
if err != nil {
5052
if err == sql.ErrNoRows {
51-
return Unathorized
53+
return -1, Unathorized
5254
}
5355
log.Println(err)
54-
return InternalServerError
56+
return -1, InternalServerError
5557
}
5658

57-
return nil
59+
return userID, nil
5860
}
5961

6062
func CreateSessionKey(userID int) (string, error) {

backend/server/ws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (handler *wsHandler) ServeHTTP(writer http.ResponseWriter, request *http.Re
7777
return
7878
}
7979

80-
err = db.Authorize(sessionKey.Value)
80+
_, err = db.AuthenticateBySessionKey(sessionKey.Value)
8181
if err != nil {
8282
switch err {
8383
case db.Unathorized:

0 commit comments

Comments
 (0)