Skip to content

Commit

Permalink
Abstract IsPreviewModeInline expression
Browse files Browse the repository at this point in the history
  • Loading branch information
cychiuae committed Jun 19, 2024
1 parent 16224a3 commit d99f721
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/auth/handler/webapp/authflowv2/create_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (h *AuthflowV2CreatePasswordHandler) GetInlinePreviewData(w http.ResponseWr
}

func (h *AuthflowV2CreatePasswordHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get(webapp.PreviewQueryKey) == webapp.PreviewModeInline {
if webapp.IsPreviewModeInline(r) {
var previewHandler handlerwebapp.PreviewHandler
previewHandler.Preview(func() error {
data, err := h.GetInlinePreviewData(w, r)
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/handler/webapp/authflowv2/enter_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (h *AuthflowV2EnterPasswordHandler) GetInlinePreviewData(w http.ResponseWri
}

func (h *AuthflowV2EnterPasswordHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get(webapp.PreviewQueryKey) == webapp.PreviewModeInline {
if webapp.IsPreviewModeInline(r) {
var previewHandler handlerwebapp.PreviewHandler
previewHandler.Preview(func() error {
data, err := h.GetInlinePreviewData(w, r)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (h *InternalAuthflowV2SignupLoginHandler) GetInlinePreviewData(w http.Respo
}

func (h *InternalAuthflowV2SignupLoginHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, options AuthflowV2SignupServeOptions) {
if r.URL.Query().Get(webapp.PreviewQueryKey) == webapp.PreviewModeInline {
if webapp.IsPreviewModeInline(r) {
var previewHandler handlerwebapp.PreviewHandler
previewHandler.Preview(func() error {
data, err := h.GetInlinePreviewData(w, r, options)
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/handler/webapp/authflowv2/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (h *AuthflowV2LoginHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}

if r.URL.Query().Get(webapp.PreviewQueryKey) == webapp.PreviewModeInline {
if webapp.IsPreviewModeInline(r) {
var previewHandler handlerwebapp.PreviewHandler
previewHandler.Preview(func() error {
data, err := h.GetInlinePreviewData(w, r)
Expand Down
6 changes: 6 additions & 0 deletions pkg/auth/webapp/preview.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package webapp

import "net/http"

const PreviewQueryKey = "x_preview"

type PreviewMode string

const (
PreviewModeInline = "inline"
)

func IsPreviewModeInline(r *http.Request) bool {
return r.URL.Query().Get(PreviewQueryKey) == PreviewModeInline
}

0 comments on commit d99f721

Please sign in to comment.