diff --git a/internal/app/handlers/auth_handler.go b/internal/app/handlers/auth_handler.go
index b4b536b..6b28357 100644
--- a/internal/app/handlers/auth_handler.go
+++ b/internal/app/handlers/auth_handler.go
@@ -57,7 +57,9 @@ func GoogleCallback(ctx *gin.Context) {
// Logout removes the token from the user's browser. Effectively "logging them out." Routes that
// require authentication will require the user to sign back in before accessing them again.
+// This route will direct the user back to the home page.
func Logout(ctx *gin.Context) {
// TODO: Use same values as the GoogleCallback function
ctx.SetCookie("jwt_token", "", -1, "/", "localhost", false, true)
+ ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME)
}
diff --git a/internal/app/handlers/page_handler.go b/internal/app/handlers/page_handler.go
index 7f3c12c..71368e0 100644
--- a/internal/app/handlers/page_handler.go
+++ b/internal/app/handlers/page_handler.go
@@ -40,7 +40,7 @@ func CreatePage(ctx *gin.Context) {
func ProfilePage(ctx *gin.Context) {
// If not logged in, direct to the login page
if !domain.IsLoggedIn(ctx) {
- ctx.Redirect(http.StatusSeeOther, "/v1/web/login")
+ ctx.Redirect(http.StatusSeeOther, domain.WEB_LOGIN)
return
}
diff --git a/internal/app/server/server.go b/internal/app/server/server.go
index 291bc4c..7f3e608 100644
--- a/internal/app/server/server.go
+++ b/internal/app/server/server.go
@@ -58,8 +58,10 @@ func (s *Server) ConfigureAuth() *Server {
panic("Could not load env file")
}
+ redirect_domain := os.Getenv("DOMAIN")
+
var (
- redirectUrl string = "http://localhost:3000/v1/api/auth/callback"
+ redirectUrl string = fmt.Sprintf("%s%s", redirect_domain, domain.API_AUTH_CALLBACK)
clientId string = os.Getenv("GOOGLE_CLIENT_ID")
clientSecret string = os.Getenv("GOOGLE_CLIENT_SECRET")
scope []string = []string{
@@ -124,14 +126,14 @@ func (s *Server) Setup() *Server {
s.Router.Use(JwtAuthMiddleWare(jwtSecret))
// Redirect index to home page: Update this as needed
- s.Router.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, "/v1/web/home") })
+ s.Router.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) })
// Wrap all routes with a version
- router_v1 := s.Router.Group("/v1")
+ router_v1 := s.Router.Group(domain.VERSION)
// Domain specific routers
- router_web := router_v1.Group("/web")
- router_api := router_v1.Group("/api")
+ router_web := router_v1.Group(domain.WEB)
+ router_api := router_v1.Group(domain.API)
// Static routes
router_web.Static("/static", "./web/static")
@@ -151,8 +153,8 @@ func (s *Server) Setup() *Server {
})
// WEB router endpoints
+ router_web.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, domain.WEB_HOME) })
router_web.GET("/login", handlers.LoginPage)
- router_web.GET("/", func(ctx *gin.Context) { ctx.Redirect(http.StatusSeeOther, "/v1/web/home") })
router_web.GET("/home", handlers.HomePage)
router_web.GET("/favorites", handlers.FavoritesPage)
router_web.GET("/create", handlers.CreatePage)
diff --git a/internal/domain/recipe/recipe.go b/internal/domain/recipe/recipe.go
deleted file mode 100644
index e69de29..0000000
diff --git a/internal/domain/recipe/repository.go b/internal/domain/recipe/repository.go
deleted file mode 100644
index e69de29..0000000
diff --git a/internal/domain/recipe/service.go b/internal/domain/recipe/service.go
deleted file mode 100644
index e69de29..0000000
diff --git a/internal/domain/server/routes.go b/internal/domain/server/routes.go
new file mode 100644
index 0000000..48c96a6
--- /dev/null
+++ b/internal/domain/server/routes.go
@@ -0,0 +1,20 @@
+package domain
+
+// Sub-routes
+const VERSION = "/v1"
+const WEB = "/web"
+const API = "/api"
+
+// Web prefixed routes
+const WEB_LOGIN = VERSION + WEB + "/login"
+const WEB_INDEX = VERSION + WEB
+const WEB_HOME = VERSION + WEB + "/home"
+const WEB_FAVORITES = VERSION + WEB + "/favorites"
+const WEB_CREATE = VERSION + WEB + "/create"
+const WEB_PROFIlE = VERSION + WEB + "/profile"
+const WEB_LIST = VERSION + WEB + "/list"
+
+// API prefixed routes
+const API_AUTH_LOGIN = VERSION + API + "/auth/login"
+const API_AUTH_CALLBACK = VERSION + API + "/auth/callback"
+const API_AUTH_LOGOUT = VERSION + API + "/auth/logout"
diff --git a/internal/templates/components/navbar.templ b/internal/templates/components/navbar.templ
index b1560a5..ac23cc1 100644
--- a/internal/templates/components/navbar.templ
+++ b/internal/templates/components/navbar.templ
@@ -1,6 +1,7 @@
package components
import "strings"
+import "github.com/haydenhargreaves/Potion/internal/domain/server"
templ hamburgerMenu() {
- @dropdownLink("Home", "/v1/web/home")
- @dropdownLink("Favorites", "/v1/web/favorites")
- @dropdownLink("Create", "/v1/web/create")
- @dropdownLink("Profile", "/v1/web/profile")
- @dropdownLink("Shopping List", "/v1/web/list")
+ @dropdownLink("Home", domain.WEB_HOME)
+ @dropdownLink("Favorites", domain.WEB_FAVORITES)
+ @dropdownLink("Create", domain.WEB_CREATE)
+ @dropdownLink("Profile", domain.WEB_PROFIlE)
+ @dropdownLink("Shopping List", domain.WEB_LIST)
}
@@ -67,11 +68,11 @@ templ Navbar(current string) {
Potion
- @navLink(current, "Home", "/v1/web/home")
- @navLink(current, "Favorites", "/v1/web/favorites")
- @navLink(current, "Create", "/v1/web/create")
- @navLink(current, "Profile", "/v1/web/profile")
- @listIcon(current, "List", "/v1/web/list")
+ @navLink(current, "Home", domain.WEB_HOME)
+ @navLink(current, "Favorites", domain.WEB_FAVORITES)
+ @navLink(current, "Create", domain.WEB_CREATE)
+ @navLink(current, "Profile", domain.WEB_PROFIlE)
+ @listIcon(current, "List", domain.WEB_LIST)