Created
December 29, 2021 11:12
-
-
Save edmundhung/6bfc50821dbd88e258d41ac2f8c3d620 to your computer and use it in GitHub Desktop.
Using remix-auth 2 with Cloudflare Workers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./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