JSPM

remix-auth-douyin

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q13069F
  • License Apache-2.0

抖音 for Remix Auth

Package Exports

  • remix-auth-douyin
  • remix-auth-douyin/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remix-auth-douyin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

DouyinStrategy

The Douyin strategy is used to authenticate users against a Douyin account. It extends the OAuth2Strategy.

Supported runtimes

Runtime Has Support
Node.js
Cloudflare

Usage

Create an OAuth application

Follow the steps on the Douyin(抖音) documentation to create a new application and get a client ID and secret.

Create the strategy instance

import { DouyinStrategy } from "remix-auth-douyin";

let douyinStrategy = new DouyinStrategy(
  {
    clientID: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    callbackURL: "https://example.com/auth/douyin/callback",
  },
  async ({ profile }) => {
    // Get the user data from your DB or API using the profile
    return User.findOrCreate({
      id: profile.id,
      name: profile.displayName,
      avatar: profile.photos[0]?.value
    });
  }
);

authenticator.use(douyinStrategy);

Setup your routes

// app/routes/login.tsx
export default function Login() {
  return (
    <Form action="/auth/douyin" method="post">
      <button>Login with Douyin(抖音)</button>
    </Form>
  );
}
// app/routes/auth.douyin.tsx
import type { ActionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { authenticator } from "~/auth.server";

export async function loader() {
  return redirect("/login");
}

export async function action({ request }: ActionArgs) {
  return authenticator.authenticate("douyin", request);
};
// app/routes/auth.douyin.callback.tsx
import type { LoaderArgs } from "@remix-run/node";
import { authenticator } from "~/auth.server";

export async function loader({ request }: LoaderArgs) {
  return authenticator.authenticate("douyin", request, {
    successRedirect: "/dashboard",
    failureRedirect: "/login",
  });
};