attempted upgrade
This commit is contained in:
@@ -46,7 +46,7 @@ class Logger {
|
||||
constructor(context?: string, options: LoggerOptions = {}) {
|
||||
this.context = context;
|
||||
this.options = {
|
||||
enabled: process.env.NODE_ENV !== "production",
|
||||
enabled: import.meta.env.NODE_ENV !== "production",
|
||||
showTimestamp: true,
|
||||
collapsed: true,
|
||||
colors: true,
|
||||
|
||||
@@ -4,12 +4,19 @@ import { createTournamentsService } from "./services/tournaments";
|
||||
import { createTeamsService } from "./services/teams";
|
||||
import { createMatchesService } from "./services/matches";
|
||||
import { createReactionsService } from "./services/reactions";
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
class PocketBaseAdminClient {
|
||||
private pb: PocketBase;
|
||||
public authPromise: Promise<void>;
|
||||
|
||||
constructor() {
|
||||
console.log('Environment variables loaded:', {
|
||||
POCKETBASE_URL: process.env.POCKETBASE_URL,
|
||||
POCKETBASE_ADMIN_EMAIL: process.env.POCKETBASE_ADMIN_EMAIL,
|
||||
POCKETBASE_ADMIN_PASSWORD: process.env.POCKETBASE_ADMIN_PASSWORD,
|
||||
});
|
||||
this.pb = new PocketBase(process.env.POCKETBASE_URL);
|
||||
|
||||
this.pb.beforeSend = (url, options) => {
|
||||
|
||||
@@ -6,23 +6,24 @@ import UserRoles from "supertokens-node/recipe/userroles";
|
||||
import { appInfo } from "./config";
|
||||
import PasswordlessDevelopmentMode from "./recipes/passwordless-development-mode";
|
||||
import { logger } from "./";
|
||||
import passwordlessTwilioVerify from "./recipes/passwordless-twilio-verify";
|
||||
|
||||
export const backendConfig = (): TypeInput => {
|
||||
return {
|
||||
framework: "custom",
|
||||
supertokens: {
|
||||
connectionURI:
|
||||
process.env.SUPERTOKENS_URI || "https://try.supertokens.io",
|
||||
import.meta.env.SUPERTOKENS_URI || "https://try.supertokens.io",
|
||||
},
|
||||
appInfo,
|
||||
recipeList: [
|
||||
PasswordlessDevelopmentMode.init(),
|
||||
Session.init({
|
||||
cookieSameSite: "lax",
|
||||
cookieSecure: process.env.NODE_ENV === "production",
|
||||
cookieSecure: import.meta.env.NODE_ENV === "production",
|
||||
cookieDomain:
|
||||
process.env.NODE_ENV === "production" ? ".example.com" : undefined,
|
||||
antiCsrf: process.env.NODE_ENV === "production" ? "VIA_TOKEN" : "NONE",
|
||||
import.meta.env.NODE_ENV === "production" ? ".example.com" : undefined,
|
||||
antiCsrf: import.meta.env.NODE_ENV === "production" ? "VIA_TOKEN" : "NONE",
|
||||
|
||||
// Debug only
|
||||
exposeAccessTokenToFrontendInCookieBasedAuth: true,
|
||||
@@ -30,13 +31,13 @@ export const backendConfig = (): TypeInput => {
|
||||
Dashboard.init(),
|
||||
UserRoles.init(),
|
||||
],
|
||||
telemetry: process.env.NODE_ENV !== "production",
|
||||
telemetry: import.meta.env.NODE_ENV !== "production",
|
||||
};
|
||||
};
|
||||
|
||||
let initialized = false;
|
||||
export function ensureSuperTokensBackend() {
|
||||
if (!initialized) {
|
||||
if (!initialized && typeof window === 'undefined') {
|
||||
SuperTokens.init(backendConfig());
|
||||
initialized = true;
|
||||
logger.simple("Backend initialized");
|
||||
|
||||
@@ -1,13 +1,23 @@
|
||||
import twilio from "twilio";
|
||||
import type { Twilio } from "twilio";
|
||||
|
||||
const accountSid = process.env.TWILIO_ACCOUNT_SID!;
|
||||
const authToken = process.env.TWILIO_AUTH_TOKEN!;
|
||||
const serviceSid = process.env.TWILIO_SERVICE_SID!;
|
||||
const accountSid = import.meta.env.TWILIO_ACCOUNT_SID!;
|
||||
const authToken = import.meta.env.TWILIO_AUTH_TOKEN!;
|
||||
const serviceSid = import.meta.env.TWILIO_SERVICE_SID!;
|
||||
|
||||
const client = twilio(accountSid, authToken);
|
||||
let client: Twilio;
|
||||
|
||||
function getTwilioClient() {
|
||||
if (!client) {
|
||||
const twilio = require("twilio");
|
||||
client = twilio(accountSid, authToken);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
export async function sendVerifyCode(phoneNumber: string, code: string) {
|
||||
const verification = await client.verify.v2
|
||||
const twilioClient = getTwilioClient();
|
||||
|
||||
const verification = await twilioClient!.verify.v2
|
||||
.services(serviceSid)
|
||||
.verifications.create({
|
||||
channel: "sms",
|
||||
@@ -23,7 +33,9 @@ export async function sendVerifyCode(phoneNumber: string, code: string) {
|
||||
}
|
||||
|
||||
export async function updateVerify(sid: string) {
|
||||
const verification = await client.verify.v2
|
||||
const twilioClient = getTwilioClient();
|
||||
|
||||
const verification = await twilioClient!.verify.v2
|
||||
.services(serviceSid)
|
||||
.verifications(sid)
|
||||
.update({ status: "approved" });
|
||||
@@ -31,4 +43,4 @@ export async function updateVerify(sid: string) {
|
||||
if (verification.status !== "approved") {
|
||||
throw new Error("Unknown error updating verification");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user