How to embed BrowserID login button in the defaultLayout

145 views Asked by At

Part of the beauty of BrowserID is that it requires very little in the way of infrastructure on your website, you simply embed a button with some javascript and then setup a callback route to handle the post-authentication data. I would like to be able to embed the BrowserID login button at the top of all of my pages inside of the defaultLayout template (and then conditionally show/hide it based on the login state), but I currently see no way to do this. The Auth subsite works by embedding its "login page" inside of the defaultLayout template, but aside from that seems to be a complete blackbox.

I'd really like to be able to avoid either rolling my own handler for BrowserID login or redirecting the user to a completely seperate page that just has a single BrowserID login button on it if at all possible.

Is there a way to accomplish what I'm trying to do that I'm just missing, or is my best bet really to roll my own BrowserID login code?

Looking at the source code for the Yesod.Auth.BrowserId module it looks like I might be able to do something like:

(apLogin authBrowserId) <not sure what would go here>

in order to get the login widget, but hijacking the guts of the plugin like that feels dirty.

1

There are 1 answers

1
Michael Snoyman On BEST ANSWER

You can use createOnClick to generate a Javascript function, and then insert whatever kind of button/link/image on your page. Just attach a click handler and have it call that function.