feat: basic auth shit + db init
This commit is contained in:
parent
db49da5fd9
commit
d8caef7e5d
10 changed files with 261 additions and 69 deletions
|
@ -8,4 +8,5 @@ import (
|
|||
func Register(cfg *types.StereoConfig) {
|
||||
api := cfg.Router.Group("/api")
|
||||
routes.RegisterUploadRoutes(cfg, api)
|
||||
routes.RegisterAuthRoutes(cfg, api)
|
||||
}
|
||||
|
|
28
internal/api/routes/auth.go
Normal file
28
internal/api/routes/auth.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"stereo.cat/backend/internal/types"
|
||||
)
|
||||
|
||||
func RegisterAuthRoutes(cfg *types.StereoConfig, api *gin.RouterGroup) {
|
||||
api.GET("/auth/callback", func(c *gin.Context) {
|
||||
code := c.Query("code")
|
||||
|
||||
t, err := cfg.Client.ExchangeCode(code)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
user, err := cfg.Client.GetUser(t)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, user)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue