B2B-88: add starter kit structure and elements

This commit is contained in:
devmc-ee
2025-06-08 16:18:30 +03:00
parent 657a36a298
commit e7b25600cb
1280 changed files with 77893 additions and 5688 deletions

View File

@@ -0,0 +1,71 @@
import Link from 'next/link';
import type { AuthError } from '@supabase/supabase-js';
import { ResendAuthLinkForm } from '@kit/auth/resend-email-link';
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
import { Button } from '@kit/ui/button';
import { Trans } from '@kit/ui/trans';
import pathsConfig from '~/config/paths.config';
import { withI18n } from '~/lib/i18n/with-i18n';
interface AuthCallbackErrorPageProps {
searchParams: Promise<{
error: string;
callback?: string;
email?: string;
code?: AuthError['code'];
}>;
}
async function AuthCallbackErrorPage(props: AuthCallbackErrorPageProps) {
const { error, callback, code } = await props.searchParams;
const signInPath = pathsConfig.auth.signIn;
const redirectPath = callback ?? pathsConfig.auth.callback;
return (
<div className={'flex flex-col space-y-4 py-4'}>
<Alert variant={'warning'}>
<AlertTitle>
<Trans i18nKey={'auth:authenticationErrorAlertHeading'} />
</AlertTitle>
<AlertDescription>
<Trans i18nKey={error ?? 'auth:authenticationErrorAlertBody'} />
</AlertDescription>
</Alert>
<AuthCallbackForm
code={code}
signInPath={signInPath}
redirectPath={redirectPath}
/>
</div>
);
}
function AuthCallbackForm(props: {
signInPath: string;
redirectPath?: string;
code?: AuthError['code'];
}) {
switch (props.code) {
case 'otp_expired':
return <ResendAuthLinkForm redirectPath={props.redirectPath} />;
default:
return <SignInButton signInPath={props.signInPath} />;
}
}
function SignInButton(props: { signInPath: string }) {
return (
<Button className={'w-full'} asChild>
<Link href={props.signInPath}>
<Trans i18nKey={'auth:signIn'} />
</Link>
</Button>
);
}
export default withI18n(AuthCallbackErrorPage);

View File

@@ -1,24 +1,18 @@
import { createClient } from "@/utils/supabase/server";
import { NextResponse } from "next/server";
import { redirect } from 'next/navigation';
import type { NextRequest } from 'next/server';
export async function GET(request: Request) {
// The `/auth/callback` route is required for the server-side auth flow implemented
// by the SSR package. It exchanges an auth code for the user's session.
// https://supabase.com/docs/guides/auth/server-side/nextjs
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get("code");
const origin = requestUrl.origin;
const redirectTo = requestUrl.searchParams.get("redirect_to")?.toString();
import { createAuthCallbackService } from '@kit/supabase/auth';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
if (code) {
const supabase = await createClient();
await supabase.auth.exchangeCodeForSession(code);
}
import pathsConfig from '~/config/paths.config';
if (redirectTo) {
return NextResponse.redirect(`${origin}${redirectTo}`);
}
export async function GET(request: NextRequest) {
const service = createAuthCallbackService(getSupabaseServerClient());
// URL to redirect to after sign up process completes
return NextResponse.redirect(`${origin}/protected`);
const { nextPath } = await service.exchangeCodeForSession(request, {
joinTeamPath: pathsConfig.app.joinTeam,
redirectPath: pathsConfig.app.home,
});
return redirect(nextPath);
}