Skip to content

Instantly share code, notes, and snippets.

@edmundhung
Created December 29, 2021 11:12
Show Gist options
  • Save edmundhung/6bfc50821dbd88e258d41ac2f8c3d620 to your computer and use it in GitHub Desktop.
Save edmundhung/6bfc50821dbd88e258d41ac2f8c3d620 to your computer and use it in GitHub Desktop.
Using remix-auth 2 with Cloudflare Workers
// ./worker/index.{js,ts}
import { createEventHandler } from "@remix-run/cloudflare-workers";
import { Authenticator } from 'remix-auth/build/authenticator';
import {
GitHubProfile,
GitHubStrategy,
} from 'remix-auth/build/strategies/github';
import * as build from "../build";
function createAuthenticator() {
let sessionStorage = createCookieSessionStorage({
cookie: {
// ....
},
});
let authenticator = new Authenticator(sessionStorage);
authenticator.use(
new GitHubStrategy({ ... })
);
return authenticator;
}
addEventListener("fetch", createEventHandler({
build,
getLoadContext() {
return {
authenticator: createAuthenticator(REMIX_AUTH),
};
},
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment