From 7760129db25a71ff6a5181a794371aa535a87ff4 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Sun, 26 Jan 2025 01:47:46 +0000 Subject: [PATCH] Convert RenderButtonTemplate to TemplateContext --- auth/providers/oauth.go | 14 +++++++++----- auth/providers/passkey.go | 9 ++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/auth/providers/oauth.go b/auth/providers/oauth.go index f811532..f1e2f56 100644 --- a/auth/providers/oauth.go +++ b/auth/providers/oauth.go @@ -11,7 +11,6 @@ import ( "github.com/1f349/lavender/url" "github.com/google/uuid" "golang.org/x/oauth2" - "html/template" "net/http" "time" ) @@ -101,11 +100,16 @@ func (o OAuthLogin) OAuthCallback(rw http.ResponseWriter, req *http.Request, inf redirect(rw, req) } -func (o OAuthLogin) ButtonName() string { return o.Name() } - -func (o OAuthLogin) RenderButtonTemplate(ctx context.Context, req *http.Request) template.HTML { +func (o OAuthLogin) RenderButtonTemplate(ctx authContext.TemplateContext) { // o.authUrlBase("button") - return "
OAuth Login Template
" + // provide something non-nil + ctx.Render(struct { + Href string + ButtonName string + }{ + Href: o.authUrlBase("button").String(), + ButtonName: "Login with Unknown OAuth Button", // TODO: actually get the service name + }) } type oauthServiceLogin int diff --git a/auth/providers/passkey.go b/auth/providers/passkey.go index e05e46c..a9b02d8 100644 --- a/auth/providers/passkey.go +++ b/auth/providers/passkey.go @@ -1,10 +1,8 @@ package providers import ( - "context" "github.com/1f349/lavender/auth" - "html/template" - "net/http" + "github.com/1f349/lavender/auth/authContext" ) type passkeyLoginDB interface { @@ -24,6 +22,7 @@ func (p *PasskeyLogin) AccessState() auth.State { return auth.StateUnauthorized func (p *PasskeyLogin) Name() string { return "passkey" } -func (p *PasskeyLogin) RenderButtonTemplate(ctx context.Context, req *http.Request) template.HTML { - return "
Passkey Button
" +func (p *PasskeyLogin) RenderButtonTemplate(ctx authContext.TemplateContext) { + // provide something non-nil + ctx.Render(struct{}{}) }