75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
import SuperTokens from "supertokens-node";
|
|
import ThirdPartyNode from "supertokens-node/recipe/thirdparty"
|
|
import SessionNode from 'supertokens-node/recipe/session'
|
|
import Dashboard from "supertokens-node/recipe/dashboard";
|
|
import UserRoles from "supertokens-node/recipe/userroles"
|
|
import { appInfo } from './appInfo'
|
|
import { TypeInput } from "supertokens-node/types";
|
|
import { configs } from './configs'
|
|
|
|
const apiKey = configs.supertokensApiKeys.split(',').at(0)
|
|
|
|
export const backendConfig = (): TypeInput => {
|
|
return {
|
|
framework: "custom",
|
|
supertokens: {
|
|
apiKey,
|
|
connectionURI: configs.supertokensUrl
|
|
},
|
|
appInfo,
|
|
recipeList: [
|
|
Dashboard.init({
|
|
admins: [
|
|
"cj@futureporn.net",
|
|
],
|
|
}),
|
|
UserRoles.init(),
|
|
ThirdPartyNode.init({
|
|
// We have provided you with development keys which you can use for testing.
|
|
// IMPORTANT: Please replace them with your own OAuth keys for production use.
|
|
signInAndUpFeature: {
|
|
providers: [{
|
|
config: {
|
|
requireEmail: false,
|
|
authorizationEndpoint: 'https://www.patreon.com/oauth2/authorize',
|
|
tokenEndpoint: 'https://www.patreon.com/api/oauth2/token',
|
|
userInfoEndpoint: 'https://www.patreon.com/api/oauth2/v2/identity',
|
|
name: 'Patreon',
|
|
thirdPartyId: 'patreon',
|
|
clients: [{
|
|
scope: ['identity', 'identity.memberships'],
|
|
clientId: configs.patreonClientId,
|
|
clientSecret: configs.patreonClientSecret
|
|
}],
|
|
userInfoEndpointQueryParams: {
|
|
// 'include': 'memberships,memberships.currently_entitled_tiers,memberships.currently_entitled_tiers.benefits,memberships.campaign',
|
|
'fields[user]': 'full_name,email',
|
|
// 'fields[member]': 'full_name,is_follower,patron_status,currently_entitled_amount_cents,campaign_lifetime_support_cents',
|
|
// 'fields[tier]': 'title',
|
|
// 'fields[benefit]': 'title',
|
|
},
|
|
userInfoMap: {
|
|
fromUserInfoAPI: {
|
|
userId: "data.id", // Maps to the "id" field under "data"
|
|
email: "data.attributes.email", // Maps to the "email" field in "data.attributes"
|
|
}
|
|
}
|
|
}
|
|
},
|
|
],
|
|
}
|
|
}),
|
|
SessionNode.init(),
|
|
],
|
|
isInServerlessEnv: true,
|
|
}
|
|
}
|
|
|
|
let initialized = false;
|
|
// This function is used in your APIs to make sure SuperTokens is initialised
|
|
export function ensureSuperTokensInit() {
|
|
if (!initialized) {
|
|
SuperTokens.init(backendConfig());
|
|
initialized = true;
|
|
}
|
|
} |