The toddle editor previews toddle pages/components in an iframe. In order to work with authenticated APIs, it's necessary to run a browser extension that helps setting cookies in the iframe. This is normally restricted by the browser since the editor and the iframe run on 2 different origins.
This repository holds code for the relevant browser extensions - 1 for Chrome and 1 for Firefox.
The extension(s) are responsible for 3 things:
- Setting cookies in the iframe when (fetch) requests return Set-Cookie headers
- Removing cookies in the iframe when (fetch) requests return
Set-Cookie
headers with an empty value for a cookie - Copying cookies from the editor --> the iframe. This is useful when working with authenticated APIs where you're already logged in for instance.
- Build the Chrome extension using
bun run build:chrome
- Open the "Extensions" page
- Click "Load unpacked"
- Select the
chrome/
folder in thedist/
folder - Click "Inspect views
service worker
" to see its output (console.log
s, exceptions etc.)
- Build the Firefox extension using
bun run build:firefox
- Open
about:debugging#/runtime/this-firefox
in Firefox - Click "Load Temporary Add-on"
- Select the manifest from the
dist/
folder - Click "Inspect" on the installed extension to see its output (
console.log
s, exceptions etc.)
To test the different aspects of the extensions, it's recommended to:
- Run an app that sets an
access_token
(or any cookie) using theSet session cookies
action. Verify the cookie is actually set for the iframe (on the*.toddle.site
domain) - Call the
/.toddle/logout
endpoint to clear theaccess_token
cookie, and verify the cookie actually gets removed from the iframe - After logging in outside of the iframe on your preview domain (
*.toddle.site
), verify that you're still logged in when opening the project in the editor
For now, we use this project for testing: https://erik_auth.toddle.site/ Everyone should be able to sign up and test login/logout on the login screen.
- Currently, setting/removing cookies in the extensions doesn't block network requests. Hence, if you remove a cookie and immediately request your session, the session call will still include the cookie.
- Allow blocking requests while adding/removing cookies to ensure future requests have the correct cookies
- Add a Safari extension
Feel free to open an issue or a PR if you find a bug/feature that you feel we should address. You can always reach out on Discord