Skip to content
LightNet v4 is here! Learn how to upgrade your site

Set up GitHub authentication

This guide shows you how to set up a GitHub App and configure a Cloudflare Worker so editors can sign in to the Administration UI with their GitHub accounts and save content changes to your site’s repository.

Your site’s Worker handles sign-in at /_auth. If you already use a separate authenticator, follow Move an existing authenticator into your site.

  • Have a LightNet site with the Administration UI and a GitHub repository.
  • Use a GitHub account with permission to create and install a GitHub App for the repository owner. For an organization-owned repository, an organization owner can do both.
  • Deploy your site to Cloudflare Workers and make sure you can manage the Worker in the Cloudflare dashboard. See the hosting guide.
  • Set site in astro.config.mjs to the public URL editors use, such as https://my-library.org. If your site uses its workers.dev address, use that URL.

From the root of your site project, run pnpm update to update your installed dependencies, including @lightnet/sveltia-admin.

Step 1. Connect the Administration UI to GitHub

Section titled “Step 1. Connect the Administration UI to GitHub”

In astro.config.mjs, add or update backend in your existing lightnetSveltiaAdmin integration. Set repo to your site’s repository in owner/repository format.

astro.config.mjs
// ...
export default defineConfig({
site: "https://my-library.org",
integrations: [
// ...
lightnetSveltiaAdmin({
backend: {
name: "github",
repo: "your-org/your-site",
},
}),
],
});

For a new setup on your site’s Worker, leave baseUrl unset. The Administration UI defaults to /_auth on your site’s origin.

The LightNet CLI fills in the GitHub App form, installs @lightnet/sveltia-github-auth if needed, and updates wrangler.jsonc. Use the manual tab if your setup requires manual configuration. See When to set it up by hand.

  1. Install the LightNet CLI from the root of your site project if needed.

    Terminal window
    pnpm add -D @lightnet/cli@latest
  2. Run the setup command from the same folder and follow the CLI prompts.

    Terminal window
    pnpm lightnet setup-github-auth
  1. Open the Administration UI on your site’s public URL, for example https://my-library.org/admin. If you configured a custom Administration UI path, use that path.
  2. Choose the GitHub sign-in option. Use a GitHub account with write access to the repository and authorize the app when prompted.
  3. Open a collection and check that its entries load. If sign-in fails, see Troubleshooting.

Give each editor write access to the site’s GitHub repository, either as a collaborator or through an organization team. Editors sign in with their own GitHub accounts and authorize the app the first time.

Move an existing authenticator into your site

Section titled “Move an existing authenticator into your site”

Follow this procedure if your site is deployed to Cloudflare Workers and currently uses a separate authenticator.

  1. Follow steps 1 and 2 to deploy authentication on your site’s Worker and add the client secret. Keep your existing baseUrl in place during these steps.

    The CLI creates a new GitHub App. To reuse a GitHub App dedicated to this site, take the Client ID from the existing app and start at the Worker package installation in the Manually tab. Use the app’s existing secret if you have it, or generate a new one in GitHub.

  2. Remove baseUrl from backend. Commit, push, and wait for Cloudflare to deploy the change. If you reused the GitHub App, update its first Callback URL to the site’s new callback, for example https://my-library.org/_auth/callback. Sign-in may be interrupted between the deployment and the callback change.

  3. Follow step 3 in a private browser window to test a fresh sign-in. If you created a new app, editors authorize it on their next sign-in.

  4. Once the test succeeds, delete the old Worker and archive its repository if they serve only this site. If you created a new app and the old app serves only this site, remove the old app from Developer settings.

What you see What to check
“You don’t have access to the repository” Open the GitHub App’s Install App settings and confirm that the app is installed on your site’s repository. Also check that the GitHub account you’re signing in with has write access.
“Your domain is not allowed to use the authenticator” Open the Administration UI on the public URL in site.
The sign-in window opens your old URL or shows “Your Git backend is not supported by the authenticator” Check the GitHub App’s first callback URL. See Switch to your own domain.
“Variables cannot be added to a Worker that only has static assets” Wait for the deployment that includes main in wrangler.jsonc to succeed, then add the secret again.
“GitHub client ID or secret is not configured” Check GITHUB_CLIENT_ID in the authenticator’s deployed wrangler.jsonc and GITHUB_CLIENT_SECRET in that Worker’s settings.
The sign-in window shows your site’s 404 page Check that package.json includes @lightnet/sveltia-github-auth and that the deployed wrangler.jsonc has the main and run_worker_first settings from step 2.
Editors have to sign in again every eight hours Check the authenticator’s version of @lightnet/sveltia-github-auth. Versions before 1.2.0 can’t refresh expiring access tokens.