prettier fix
This commit is contained in:
@@ -16,14 +16,16 @@ const AppConfigSchema = z
|
||||
})
|
||||
.describe(`This is the default title tag of your SaaS.`)
|
||||
.min(1),
|
||||
description: z.string({
|
||||
error: `Please provide the variable NEXT_PUBLIC_SITE_DESCRIPTION`,
|
||||
})
|
||||
description: z
|
||||
.string({
|
||||
error: `Please provide the variable NEXT_PUBLIC_SITE_DESCRIPTION`,
|
||||
})
|
||||
.describe(`This is the default description of your SaaS.`),
|
||||
url: z.url({
|
||||
error: (issue) => issue.input === undefined
|
||||
? "Please provide the variable NEXT_PUBLIC_SITE_URL"
|
||||
: `You are deploying a production build but have entered a NEXT_PUBLIC_SITE_URL variable using http instead of https. It is very likely that you have set the incorrect URL. The build will now fail to prevent you from from deploying a faulty configuration. Please provide the variable NEXT_PUBLIC_SITE_URL with a valid URL, such as: 'https://example.com'`
|
||||
error: (issue) =>
|
||||
issue.input === undefined
|
||||
? 'Please provide the variable NEXT_PUBLIC_SITE_URL'
|
||||
: `You are deploying a production build but have entered a NEXT_PUBLIC_SITE_URL variable using http instead of https. It is very likely that you have set the incorrect URL. The build will now fail to prevent you from from deploying a faulty configuration. Please provide the variable NEXT_PUBLIC_SITE_URL with a valid URL, such as: 'https://example.com'`,
|
||||
}),
|
||||
locale: z
|
||||
.string({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Provider } from '@supabase/supabase-js';
|
||||
|
||||
import authConfig from './auth.config';
|
||||
|
||||
type SupabaseExternalProvider = Provider | 'email';
|
||||
@@ -10,7 +11,10 @@ interface SupabaseAuthSettings {
|
||||
|
||||
export class AuthProvidersService {
|
||||
private supabaseUrl: string;
|
||||
private cache: Map<string, { data: SupabaseAuthSettings; timestamp: number }> = new Map();
|
||||
private cache: Map<
|
||||
string,
|
||||
{ data: SupabaseAuthSettings; timestamp: number }
|
||||
> = new Map();
|
||||
private readonly CACHE_TTL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
constructor(supabaseUrl: string) {
|
||||
@@ -21,7 +25,7 @@ export class AuthProvidersService {
|
||||
try {
|
||||
const cacheKey = 'auth-settings';
|
||||
const cached = this.cache.get(cacheKey);
|
||||
|
||||
|
||||
if (cached && Date.now() - cached.timestamp < this.CACHE_TTL) {
|
||||
return cached.data;
|
||||
}
|
||||
@@ -31,22 +35,28 @@ export class AuthProvidersService {
|
||||
throw new Error('NEXT_PUBLIC_SUPABASE_ANON_KEY is required');
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.supabaseUrl}/auth/v1/settings?apikey=${anonKey}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
const response = await fetch(
|
||||
`${this.supabaseUrl}/auth/v1/settings?apikey=${anonKey}`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
console.warn('Failed to fetch auth settings from Supabase:', response.status);
|
||||
console.warn(
|
||||
'Failed to fetch auth settings from Supabase:',
|
||||
response.status,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const settings: SupabaseAuthSettings = await response.json();
|
||||
|
||||
|
||||
this.cache.set(cacheKey, { data: settings, timestamp: Date.now() });
|
||||
|
||||
|
||||
return settings;
|
||||
} catch (error) {
|
||||
console.warn('Error fetching auth settings from Supabase:', error);
|
||||
@@ -54,7 +64,11 @@ export class AuthProvidersService {
|
||||
}
|
||||
}
|
||||
|
||||
isPasswordEnabled({ settings }: { settings: SupabaseAuthSettings | null }): boolean {
|
||||
isPasswordEnabled({
|
||||
settings,
|
||||
}: {
|
||||
settings: SupabaseAuthSettings | null;
|
||||
}): boolean {
|
||||
if (settings) {
|
||||
return settings.external.email === true && !settings.disable_signup;
|
||||
}
|
||||
@@ -62,7 +76,11 @@ export class AuthProvidersService {
|
||||
return process.env.NEXT_PUBLIC_AUTH_PASSWORD === 'true';
|
||||
}
|
||||
|
||||
isMailerAutoconfirmEnabled({ settings }: { settings: SupabaseAuthSettings | null }): boolean {
|
||||
isMailerAutoconfirmEnabled({
|
||||
settings,
|
||||
}: {
|
||||
settings: SupabaseAuthSettings | null;
|
||||
}): boolean {
|
||||
return settings?.mailer_autoconfirm === true;
|
||||
}
|
||||
|
||||
@@ -84,11 +102,17 @@ export class AuthProvidersService {
|
||||
return false;
|
||||
}
|
||||
|
||||
getEnabledOAuthProviders({ settings }: { settings: SupabaseAuthSettings | null }): SupabaseExternalProvider[] {
|
||||
getEnabledOAuthProviders({
|
||||
settings,
|
||||
}: {
|
||||
settings: SupabaseAuthSettings | null;
|
||||
}): SupabaseExternalProvider[] {
|
||||
const enabledProviders: SupabaseExternalProvider[] = [];
|
||||
|
||||
|
||||
if (settings && settings.external) {
|
||||
for (const [providerName, isEnabled] of Object.entries(settings.external)) {
|
||||
for (const [providerName, isEnabled] of Object.entries(
|
||||
settings.external,
|
||||
)) {
|
||||
if (isEnabled && providerName !== 'email') {
|
||||
enabledProviders.push(providerName as SupabaseExternalProvider);
|
||||
}
|
||||
@@ -98,19 +122,27 @@ export class AuthProvidersService {
|
||||
|
||||
const potentialProviders: SupabaseExternalProvider[] = ['keycloak'];
|
||||
const enabledFallback: SupabaseExternalProvider[] = [];
|
||||
|
||||
|
||||
for (const provider of potentialProviders) {
|
||||
if (provider !== 'email' && this.isOAuthProviderEnabled({ provider, settings })) {
|
||||
if (
|
||||
provider !== 'email' &&
|
||||
this.isOAuthProviderEnabled({ provider, settings })
|
||||
) {
|
||||
enabledFallback.push(provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return enabledFallback;
|
||||
}
|
||||
|
||||
async getAuthConfig() {
|
||||
const settings = await this.fetchAuthSettings();
|
||||
const [passwordEnabled, magicLinkEnabled, oAuthProviders, isMailerAutoconfirmEnabled] = await Promise.all([
|
||||
const [
|
||||
passwordEnabled,
|
||||
magicLinkEnabled,
|
||||
oAuthProviders,
|
||||
isMailerAutoconfirmEnabled,
|
||||
] = await Promise.all([
|
||||
this.isPasswordEnabled({ settings }),
|
||||
this.isMagicLinkEnabled(),
|
||||
this.getEnabledOAuthProviders({ settings }),
|
||||
@@ -135,10 +167,10 @@ export class AuthProvidersService {
|
||||
|
||||
export function createAuthProvidersService(): AuthProvidersService {
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
|
||||
|
||||
if (!supabaseUrl) {
|
||||
throw new Error('NEXT_PUBLIC_SUPABASE_URL is required');
|
||||
}
|
||||
|
||||
|
||||
return new AuthProvidersService(supabaseUrl);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ const providers: z.ZodType<Provider> = getProviders();
|
||||
|
||||
const AuthConfigSchema = z.object({
|
||||
captchaTokenSiteKey: z
|
||||
.string().describe('The reCAPTCHA site key.')
|
||||
.string()
|
||||
.describe('The reCAPTCHA site key.')
|
||||
.optional(),
|
||||
displayTermsCheckbox: z
|
||||
.boolean().describe('Whether to display the terms checkbox during sign-up.')
|
||||
.boolean()
|
||||
.describe('Whether to display the terms checkbox during sign-up.')
|
||||
.optional(),
|
||||
providers: z.object({
|
||||
password: z.boolean().describe('Enable password authentication.'),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { Provider } from '@supabase/supabase-js';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createAuthProvidersService } from './auth-providers.service';
|
||||
|
||||
const providers: z.ZodType<Provider> = getProviders();
|
||||
@@ -10,8 +12,12 @@ const DynamicAuthConfigSchema = z.object({
|
||||
magicLink: z.boolean().describe('Enable magic link authentication.'),
|
||||
oAuth: providers.array(),
|
||||
}),
|
||||
displayTermsCheckbox: z.boolean().describe('Whether to display the terms checkbox during sign-up.'),
|
||||
isMailerAutoconfirmEnabled: z.boolean().describe('Whether Supabase sends confirmation email automatically.'),
|
||||
displayTermsCheckbox: z
|
||||
.boolean()
|
||||
.describe('Whether to display the terms checkbox during sign-up.'),
|
||||
isMailerAutoconfirmEnabled: z
|
||||
.boolean()
|
||||
.describe('Whether Supabase sends confirmation email automatically.'),
|
||||
});
|
||||
|
||||
export type DynamicAuthConfig = {
|
||||
@@ -22,7 +28,7 @@ export type DynamicAuthConfig = {
|
||||
};
|
||||
displayTermsCheckbox: boolean | undefined;
|
||||
isMailerAutoconfirmEnabled: boolean;
|
||||
}
|
||||
};
|
||||
|
||||
export async function getDynamicAuthConfig() {
|
||||
const authService = createAuthProvidersService();
|
||||
@@ -57,10 +63,13 @@ export async function getCachedAuthConfig() {
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
sessionStorage.setItem('auth-config', JSON.stringify({
|
||||
data: config,
|
||||
timestamp: Date.now(),
|
||||
}));
|
||||
sessionStorage.setItem(
|
||||
'auth-config',
|
||||
JSON.stringify({
|
||||
data: config,
|
||||
timestamp: Date.now(),
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn('Failed to cache auth config:', error);
|
||||
}
|
||||
@@ -73,7 +82,9 @@ export async function getServerAuthConfig() {
|
||||
return getDynamicAuthConfig();
|
||||
}
|
||||
|
||||
export async function isProviderEnabled(provider: 'password' | 'magicLink' | Provider): Promise<boolean> {
|
||||
export async function isProviderEnabled(
|
||||
provider: 'password' | 'magicLink' | Provider,
|
||||
): Promise<boolean> {
|
||||
const authService = createAuthProvidersService();
|
||||
const settings = await authService.fetchAuthSettings();
|
||||
|
||||
|
||||
@@ -3,57 +3,65 @@ import { z } from 'zod';
|
||||
type LanguagePriority = 'user' | 'application';
|
||||
|
||||
const FeatureFlagsSchema = z.object({
|
||||
enableThemeToggle: z.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_THEME_TOGGLE',
|
||||
})
|
||||
.describe( 'Enable theme toggle in the user interface.'),
|
||||
enableAccountDeletion: z.boolean({
|
||||
error:
|
||||
'Provide the variable NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_DELETION',
|
||||
})
|
||||
.describe('Enable personal account deletion.'),
|
||||
enableTeamDeletion: z.boolean({
|
||||
error:
|
||||
'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION',
|
||||
})
|
||||
.describe('Enable team deletion.'),
|
||||
enableTeamAccounts: z.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS',
|
||||
})
|
||||
.describe('Enable team accounts.'),
|
||||
enableTeamCreation: z.boolean({
|
||||
error:
|
||||
'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_CREATION',
|
||||
})
|
||||
.describe('Enable team creation.'),
|
||||
enablePersonalAccountBilling: z.boolean({
|
||||
error:
|
||||
'Provide the variable NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_BILLING',
|
||||
})
|
||||
.describe('Enable personal account billing.'),
|
||||
enableTeamAccountBilling: z.boolean({
|
||||
error:
|
||||
'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_BILLING',
|
||||
})
|
||||
.describe('Enable team account billing.'),
|
||||
enableThemeToggle: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_THEME_TOGGLE',
|
||||
})
|
||||
.describe('Enable theme toggle in the user interface.'),
|
||||
enableAccountDeletion: z
|
||||
.boolean({
|
||||
error:
|
||||
'Provide the variable NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_DELETION',
|
||||
})
|
||||
.describe('Enable personal account deletion.'),
|
||||
enableTeamDeletion: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION',
|
||||
})
|
||||
.describe('Enable team deletion.'),
|
||||
enableTeamAccounts: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS',
|
||||
})
|
||||
.describe('Enable team accounts.'),
|
||||
enableTeamCreation: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_CREATION',
|
||||
})
|
||||
.describe('Enable team creation.'),
|
||||
enablePersonalAccountBilling: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_BILLING',
|
||||
})
|
||||
.describe('Enable personal account billing.'),
|
||||
enableTeamAccountBilling: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_BILLING',
|
||||
})
|
||||
.describe('Enable team account billing.'),
|
||||
languagePriority: z
|
||||
.enum(['user', 'application'], {
|
||||
error: 'Provide the variable NEXT_PUBLIC_LANGUAGE_PRIORITY',
|
||||
})
|
||||
.describe(`If set to user, use the user's preferred language. If set to application, use the application's default language.`)
|
||||
.describe(
|
||||
`If set to user, use the user's preferred language. If set to application, use the application's default language.`,
|
||||
)
|
||||
.default('application'),
|
||||
enableNotifications: z.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_NOTIFICATIONS',
|
||||
})
|
||||
.describe('Enable notifications functionality'),
|
||||
realtimeNotifications: z.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_REALTIME_NOTIFICATIONS',
|
||||
})
|
||||
.describe('Enable realtime for the notifications functionality'),
|
||||
enableVersionUpdater: z.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_VERSION_UPDATER',
|
||||
})
|
||||
.describe('Enable version updater'),
|
||||
enableNotifications: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_NOTIFICATIONS',
|
||||
})
|
||||
.describe('Enable notifications functionality'),
|
||||
realtimeNotifications: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_REALTIME_NOTIFICATIONS',
|
||||
})
|
||||
.describe('Enable realtime for the notifications functionality'),
|
||||
enableVersionUpdater: z
|
||||
.boolean({
|
||||
error: 'Provide the variable NEXT_PUBLIC_ENABLE_VERSION_UPDATER',
|
||||
})
|
||||
.describe('Enable version updater'),
|
||||
});
|
||||
|
||||
const featureFlagsConfig = FeatureFlagsSchema.parse({
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import appConfig from './app.config';
|
||||
import authConfig from './auth.config';
|
||||
import billingConfig from './billing.config';
|
||||
import {
|
||||
DynamicAuthConfig,
|
||||
getCachedAuthConfig,
|
||||
getServerAuthConfig,
|
||||
} from './dynamic-auth.config';
|
||||
import featureFlagsConfig from './feature-flags.config';
|
||||
import pathsConfig from './paths.config';
|
||||
import { personalAccountNavigationConfig } from './personal-account-navigation.config';
|
||||
@@ -8,7 +13,6 @@ import {
|
||||
createPath,
|
||||
getTeamAccountSidebarConfig,
|
||||
} from './team-account-navigation.config';
|
||||
import { DynamicAuthConfig, getCachedAuthConfig, getServerAuthConfig } from './dynamic-auth.config';
|
||||
|
||||
export {
|
||||
appConfig,
|
||||
|
||||
Reference in New Issue
Block a user