#1 add basic authorization

This commit is contained in:
Tim
2024-07-26 09:28:25 +02:00
parent d80ceb42da
commit ffd8b413a9
9 changed files with 1367 additions and 529 deletions

View File

@@ -8,6 +8,7 @@ import (
"log"
"net/http"
"firebase.google.com/go/auth"
_ "github.com/mattn/go-sqlite3"
)
@@ -37,7 +38,7 @@ func main() {
var server = http.Server{
Addr: ":8080",
Handler: middleware.Logging(router),
Handler: middleware.Logging(middleware.EnsureAuth(router)),
}
log.Println("Starting server at", server.Addr)
@@ -48,6 +49,9 @@ func main() {
}
func (ctx *Context) HelloWorld(w http.ResponseWriter, r *http.Request) {
token := r.Context().Value(middleware.TOKEN_KEY).(*auth.Token)
log.Println(token.UID)
sqlStmt := `select COUNT(*) from person;`
result, err := ctx.DB.Query(sqlStmt)