diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-06 01:55:21 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-06 02:08:58 +0800 |
commit | faa5ca8fab23176d390e9522f1485d467851545b (patch) | |
tree | d3b1d081e0ea5e7f71a94dc1d301e2540a8abcc8 /http_auth.go | |
parent | Slight refactor on NewServer (diff) | |
download | forge-faa5ca8fab23176d390e9522f1485d467851545b.tar.gz forge-faa5ca8fab23176d390e9522f1485d467851545b.tar.zst forge-faa5ca8fab23176d390e9522f1485d467851545b.zip |
Move stuff into internal/unsortedv0.1.28
Diffstat (limited to 'http_auth.go')
-rw-r--r-- | http_auth.go | 26 |
1 files changed, 0 insertions, 26 deletions
diff --git a/http_auth.go b/http_auth.go deleted file mode 100644 index 44e087d..0000000 --- a/http_auth.go +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> - -package forge - -import ( - "net/http" -) - -// getUserFromRequest returns the user ID and username associated with the -// session cookie in a given [http.Request]. -func (s *Server) getUserFromRequest(request *http.Request) (id int, username string, err error) { - var sessionCookie *http.Cookie - - if sessionCookie, err = request.Cookie("session"); err != nil { - return - } - - err = s.database.QueryRow( - request.Context(), - "SELECT user_id, COALESCE(username, '') FROM users u JOIN sessions s ON u.id = s.user_id WHERE s.session_id = $1;", - sessionCookie.Value, - ).Scan(&id, &username) - - return -} |