prefer using providers conf from supabase instead of env
This commit is contained in:
@@ -13,7 +13,8 @@ import { Button } from '@kit/ui/button';
|
||||
import { If } from '@kit/ui/if';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { authConfig, featureFlagsConfig, pathsConfig } from '@kit/shared/config';
|
||||
import { featureFlagsConfig, pathsConfig } from '@kit/shared/config';
|
||||
import { useAuthConfig } from '@kit/shared/hooks';
|
||||
|
||||
const ModeToggle = dynamic(() =>
|
||||
import('@kit/ui/mode-toggle').then((mod) => ({
|
||||
@@ -57,6 +58,8 @@ export function SiteHeaderAccountSection({
|
||||
}
|
||||
|
||||
function AuthButtons() {
|
||||
const { config } = useAuthConfig();
|
||||
|
||||
return (
|
||||
<div className={'animate-in fade-in flex gap-x-2.5 duration-500'}>
|
||||
<div className={'hidden md:flex'}>
|
||||
@@ -65,21 +68,25 @@ function AuthButtons() {
|
||||
</If>
|
||||
</div>
|
||||
|
||||
<div className={'flex gap-x-2.5'}>
|
||||
<Button className={'block'} asChild variant={'ghost'}>
|
||||
<Link href={pathsConfig.auth.signIn}>
|
||||
<Trans i18nKey={'auth:signIn'} />
|
||||
</Link>
|
||||
</Button>
|
||||
{config && (
|
||||
<div className={'flex gap-x-2.5'}>
|
||||
{(config.providers.password || config.providers.oAuth.length > 0) && (
|
||||
<Button className={'block'} asChild variant={'ghost'}>
|
||||
<Link href={pathsConfig.auth.signIn}>
|
||||
<Trans i18nKey={'auth:signIn'} />
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{authConfig.providers.password && (
|
||||
<Button asChild className="text-xs md:text-sm" variant={'default'}>
|
||||
<Link href={pathsConfig.auth.signUp}>
|
||||
<Trans i18nKey={'auth:signUp'} />
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{config.providers.password && (
|
||||
<Button asChild className="text-xs md:text-sm" variant={'default'}>
|
||||
<Link href={pathsConfig.auth.signUp}>
|
||||
<Trans i18nKey={'auth:signUp'} />
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
import { SignInMethodsContainer } from '@kit/auth/sign-in';
|
||||
import { authConfig, pathsConfig } from '@kit/shared/config';
|
||||
import { Providers, SignInMethodsContainer } from '@kit/auth/sign-in';
|
||||
import { pathsConfig } from '@kit/shared/config';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Heading } from '@kit/ui/heading';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
@@ -9,9 +9,11 @@ import { Trans } from '@kit/ui/trans';
|
||||
export default function PasswordOption({
|
||||
inviteToken,
|
||||
returnPath,
|
||||
providers,
|
||||
}: {
|
||||
inviteToken?: string;
|
||||
returnPath?: string;
|
||||
providers: Providers;
|
||||
}) {
|
||||
const signUpPath =
|
||||
pathsConfig.auth.signUp +
|
||||
@@ -39,7 +41,7 @@ export default function PasswordOption({
|
||||
<SignInMethodsContainer
|
||||
inviteToken={inviteToken}
|
||||
paths={paths}
|
||||
providers={authConfig.providers}
|
||||
providers={providers}
|
||||
/>
|
||||
|
||||
<div className={'flex justify-center'}>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { pathsConfig, authConfig } from '@kit/shared/config';
|
||||
import { getServerAuthConfig, pathsConfig } from '@kit/shared/config';
|
||||
|
||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
@@ -24,11 +24,23 @@ async function SignInPage({ searchParams }: SignInPageProps) {
|
||||
const { invite_token: inviteToken, next: returnPath = pathsConfig.app.home } =
|
||||
await searchParams;
|
||||
|
||||
const authConfig = await getServerAuthConfig();
|
||||
|
||||
if (authConfig.providers.password) {
|
||||
return <PasswordOption inviteToken={inviteToken} returnPath={returnPath} />;
|
||||
return (
|
||||
<PasswordOption
|
||||
inviteToken={inviteToken}
|
||||
returnPath={returnPath}
|
||||
providers={authConfig.providers}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <SignInPageClientRedirect />;
|
||||
if (authConfig.providers.oAuth.includes('keycloak')) {
|
||||
return <SignInPageClientRedirect />;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default withI18n(SignInPage);
|
||||
|
||||
@@ -2,7 +2,7 @@ import Link from 'next/link';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { SignUpMethodsContainer } from '@kit/auth/sign-up';
|
||||
import { authConfig, pathsConfig } from '@kit/shared/config';
|
||||
import { getServerAuthConfig, pathsConfig } from '@kit/shared/config';
|
||||
import { Button } from '@kit/ui/button';
|
||||
import { Heading } from '@kit/ui/heading';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
@@ -38,6 +38,8 @@ async function SignUpPage({ searchParams }: Props) {
|
||||
pathsConfig.auth.signIn +
|
||||
(inviteToken ? `?invite_token=${inviteToken}` : '');
|
||||
|
||||
const authConfig = await getServerAuthConfig();
|
||||
|
||||
if (!authConfig.providers.password) {
|
||||
return redirect('/');
|
||||
}
|
||||
@@ -56,9 +58,9 @@ async function SignUpPage({ searchParams }: Props) {
|
||||
|
||||
<SignUpMethodsContainer
|
||||
providers={authConfig.providers}
|
||||
displayTermsCheckbox={authConfig.displayTermsCheckbox}
|
||||
inviteToken={inviteToken}
|
||||
paths={paths}
|
||||
displayTermsCheckbox={authConfig.displayTermsCheckbox}
|
||||
/>
|
||||
|
||||
<div className={'flex justify-center'}>
|
||||
|
||||
@@ -146,14 +146,21 @@ export default function Dashboard({
|
||||
}) {
|
||||
const height = account.accountParams?.height || 0;
|
||||
const weight = account.accountParams?.weight || 0;
|
||||
const { age = 0, gender } = PersonalCode.parsePersonalCode(account.personal_code!);
|
||||
|
||||
let age: number = 0;
|
||||
let gender: { label: string; value: string } | null = null;
|
||||
try {
|
||||
({ age = 0, gender } = PersonalCode.parsePersonalCode(account.personal_code!));
|
||||
} catch (e) {
|
||||
console.error("Failed to parse personal code", e);
|
||||
}
|
||||
const bmiStatus = getBmiStatus(bmiThresholds, { age, height, weight });
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="xs:grid-cols-2 grid auto-rows-fr gap-3 sm:grid-cols-4 lg:grid-cols-5">
|
||||
{cards({
|
||||
gender: gender.label,
|
||||
gender: gender?.label,
|
||||
age,
|
||||
height,
|
||||
weight,
|
||||
|
||||
Reference in New Issue
Block a user