Still missing a UI and we do not have session management just yet, but the workflow of calling the Google API's and creating/finding users is working with the current structure.
31 lines
776 B
Go
31 lines
776 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
domain "github.com/haydenhargreaves/Potion/internal/domain/server"
|
|
)
|
|
|
|
func GoogleLogin(ctx *gin.Context) {
|
|
deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
|
url := deps.AuthService.GetGoogleAuthUrl()
|
|
|
|
ctx.Redirect(http.StatusSeeOther, url)
|
|
}
|
|
|
|
func GoogleCallback(ctx *gin.Context) {
|
|
deps := ctx.MustGet("deps").(*domain.InjectedDependencies)
|
|
|
|
var (
|
|
state string = ctx.Query("state")
|
|
code string = ctx.Query("code")
|
|
)
|
|
|
|
if dbUser, googleUserInfo, err := deps.AuthService.GoogleAuthSuccess(state, code); err != nil {
|
|
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
} else {
|
|
ctx.JSON(http.StatusOK, gin.H{"googleUserInfo": googleUserInfo, "dbUser": dbUser})
|
|
}
|
|
}
|