#1 add authorization with firebase

Co-authored-by: Tim <timwundenberg@outlook.de>
Reviewed-on: tim/me-fit#2
This commit is contained in:
2024-07-26 23:15:11 +02:00
parent 3539bf9d3e
commit 04fa4ddf68
12 changed files with 1457 additions and 532 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)