UNPKG

next-integrate

Version:

An authentication library for making integrations in your Next.js Web Application

108 lines (101 loc) 3.24 kB
import { NextRequest } from 'next/server'; export { NextRequest } from 'next/server'; import { ReadonlyRequestCookies } from 'next/dist/server/web/spec-extension/adapters/request-cookies'; type Tokens = { provider: Provider; [key: string]: any; }; type Provider = "google" | "pinterest" | "facebook" | "snapchat" | "spotify" | "slack" | "klaviyo" | "notion" | "discord" | "github" | "tiktok" | "trustpilot" | "accuranker" | "click-up" | "linkedin"; type Auth = { base_url: string; providers: { provider: Provider; client_id: string; client_secret: string; integrations: { name: string; options?: { scope?: string; response_type?: string; [key: string]: any; }; callback: (tokens: Tokens) => void; }[]; }[]; }; declare function generateAuthURL({ params, base_url, client_id, scope, code_challenge, ...props }: { params: string; base_url: string | undefined; client_id: string | undefined; scope?: string; code_challenge: string | undefined; [key: string]: string | undefined; }): Promise<string | undefined>; declare function generateTokens({ code, params, base_url, client_id, client_secret, callback, code_verifier, }: { code: string; params: string; base_url: string | undefined; client_id: string | undefined; client_secret: string | undefined; callback: (tokens: Tokens) => void; code_verifier: string | undefined; }): Promise<any>; declare function NextIntegrate(auth: Auth): { auth: Auth; }; declare function handler({ context, req, auth, cookieStore, debug, }: { context: { params: Promise<{ integration: string[]; }>; }; req: NextRequest; auth: Auth; cookieStore: Promise<ReadonlyRequestCookies>; debug?: boolean; }): Promise<{ error: string; auth_url: string; redirect: string; options: null; codeChallenge: string; callback: () => void; } | { auth_url: string; redirect: string; options: { client_id: string; client_secret: string; code_challenge: string; base_url: string; params: string; scope?: string; response_type?: string; }; callback: (tokens: Tokens) => void; error: null; }>; declare function exchange({ options, callback, code, cookieStore, debug, }: { options: { client_id: string; scope?: string; base_url: string; client_secret: string; params: string; [key: string]: string | undefined; } | null; callback: (tokens: Tokens) => void; code: string; cookieStore: Promise<ReadonlyRequestCookies>; debug?: boolean; }): Promise<Tokens | undefined>; declare function clearCookies({ cookieStore, }: { cookieStore: Promise<ReadonlyRequestCookies>; }): Promise<void>; declare function integrate({ name, provider, redirect, base_path, }: { name: string; provider: string; redirect: string; base_path?: string; }): string; export { type Auth, NextIntegrate, type Provider, type Tokens, clearCookies, exchange, generateAuthURL, generateTokens, handler, integrate };