Skip to content

Instantly share code, notes, and snippets.

@MrTin
Created August 8, 2023 14:58
Show Gist options
  • Save MrTin/d6a3dfb15516058752716e1a500654ca to your computer and use it in GitHub Desktop.
Save MrTin/d6a3dfb15516058752716e1a500654ca to your computer and use it in GitHub Desktop.
import { OAuthConfig, OAuthUserConfig } from 'next-auth/providers';
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
export interface BoltProfile extends Record<string, any> {
profile: Profile;
addresses: Address[];
// payment_methods: PaymentMethod[]; # TODO: Implement...
has_bolt_account: boolean;
}
export interface Profile extends Record<string, any> {
email: string;
first_name: string;
last_name: string;
name: string;
phone: string;
metadata: {
customer_id: string;
};
}
export interface Address extends Record<string, any> {
first_name: string;
last_name: string;
name: string;
email_address: string;
company: string;
country: string;
country_code: string;
locality: string;
phone_number: string;
postal_code: string;
region: string;
region_code: string;
street_address1: string;
street_address2: string;
street_address3: string;
street_address4: string;
door_code: number;
default: boolean;
metadata: {
customer_id: string;
};
}
export default function Bolt<P extends BoltProfile>(
options: OAuthUserConfig<P>,
): OAuthConfig<P> {
return {
id: 'bolt',
name: 'Bolt',
type: 'oauth',
wellKnown: `${publicRuntimeConfig.boltApiUrl}/.well-known/openid-configuration`,
authorization: {
params: {
scope: 'bolt.account.manage bolt.account.view openid',
// eslint-disable-next-line camelcase
redirect_uri: 'http://localhost:3000/api/auth/callback/bolt',
},
},
idToken: true,
checks: ['state', 'pkce'],
userinfo: `${publicRuntimeConfig.boltApiUrl}/v1/account`,
profile(profile) {
return {
id: profile.profile.metadata.customer_id,
name: profile.profile.name,
firstName: profile.profile.first_name,
lastName: profile.profile.last_name,
email: profile.profile.email,
};
},
options,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment