Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
function createHelpers
import { createHelpers } from "https://deno.land/x/fathym_everything_as_code@v0.0.390-integration/src/src.deps.ts";

Creates the full set of helpers with the given OAuth configuration and options.

Examples

Example 1

// server.ts
import {
  createGitHubOAuthConfig,
  createHelpers,
} from "https://deno.land/x/deno_kv_oauth@$VERSION/mod.ts";

const {
  signIn,
  handleCallback,
  signOut,
  getSessionId,
} = createHelpers(createGitHubOAuthConfig(), {
  cookieOptions: {
    name: "__Secure-triple-choc",
    domain: "news.site",
  },
});

async function handler(request: Request) {
  const { pathname } = new URL(request.url);
  switch (pathname) {
    case "/oauth/signin":
      return await signIn(request);
    case "/oauth/callback":
      const { response } = await handleCallback(request);
      return response;
    case "/oauth/signout":
      return await signOut(request);
    case "/protected-route":
      return await getSessionId(request) === undefined
        ? new Response("Unauthorized", { status: 401 })
        : new Response("You are allowed");
    default:
      return new Response(null, { status: 404 });
  }
}

Deno.serve(handler);

Returns

{ signIn(request: Request, options?: SignInOptions): Promise<Response>; handleCallback(request: Request): Promise<{ response: Response; sessionId: string; tokens: Tokens; }>; signOut(request: Request): Promise<Response>; getSessionId(request: Request): Promise<string | undefined>; }