Session Strategies
Bitbucket Strategy

Bitbucket Strategy

The Bitbucket Cloud strategy for remix-auth (opens in a new tab) is used to authenticate users against a Bitbucket Cloud account. It extends the OAuth2Strategy.

Supported runtimes

RuntimeHas Support
Node.js
Cloudflare

Setup Guide

Install the package

npm install remix-auth-bitbucket

Create the strategy instance

app/services/auth.server.ts
import { BitbucketStrategy } from "remix-auth-bitbucket";
 
let bitbucketStrategy = new BitbucketStrategy(
  {
    clientID: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    callbackURL: "https://example.com/auth/bitbucket/callback",
  },
  async ({ accessToken, extraParams, profile }) => {
    // Get the user data from your DB or API using the tokens and profile
    return User.findOrCreate({ email: profile.emails[0].value });
  }
);
 
authenticator.use(bitbucketStrategy);

Setup your routes

app/routes/login.tsx
export default function Login() {
  return (
    <Form action="/auth/bitbucket" method="post">
      <button>Login with Bitbucket</button>
    </Form>
  );
}
app/routes/auth/bitbucket.tsx
import { ActionFunction, LoaderFunction, redirect } from "remix";
import { authenticator } from "~/auth.server";
 
export let loader: LoaderFunction = () => redirect("/login");
 
export let action: ActionFunction = ({ request }) => {
  return authenticator.authenticate("bitbucket", request);
};
app/routes/auth/bitbucket/callback.tsx
import { LoaderFunction } from "remix";
import { authenticator } from "~/auth.server";
 
export let loader: LoaderFunction = ({ request }) => {
  return authenticator.authenticate("bitbucket", request, {
    successRedirect: "/dashboard",
    failureRedirect: "/login",
  });
};