Merge branch 'main' into MED-111

This commit is contained in:
Danel Kungla
2025-07-31 12:30:25 +03:00
10 changed files with 52 additions and 22 deletions

4
.env
View File

@@ -69,3 +69,7 @@ NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
MONTONIO_API_URL=https://sandbox-stargate.montonio.com MONTONIO_API_URL=https://sandbox-stargate.montonio.com
# MEDUSA
MEDUSA_BACKEND_URL=http://localhost:9000
MEDUSA_BACKEND_PUBLIC_URL=http://localhost:9000

View File

@@ -2,7 +2,7 @@
# https://app.supabase.com/project/_/settings/api # https://app.supabase.com/project/_/settings/api
NEXT_PUBLIC_SUPABASE_URL=your-project-url NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY=your-service-role-key SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
MEDIPOST_URL=your-medipost-url MEDIPOST_URL=your-medipost-url
MEDIPOST_USER=your-medipost-user MEDIPOST_USER=your-medipost-user

View File

@@ -39,7 +39,17 @@ async function VerifyPage(props: Props) {
redirect(pathsConfig.auth.signIn); redirect(pathsConfig.auth.signIn);
} }
return <MultiFactorChallengeContainer userId={user.id} />; const nextPath = (await props.searchParams).next;
const redirectPath = nextPath ?? pathsConfig.app.home;
return (
<MultiFactorChallengeContainer
userId={user.id}
paths={{
redirectPath,
}}
/>
);
} }
export default withI18n(VerifyPage); export default withI18n(VerifyPage);

View File

@@ -30,8 +30,7 @@ async function syncData() {
const password = process.env.MEDIPOST_PASSWORD; const password = process.env.MEDIPOST_PASSWORD;
const sender = process.env.MEDIPOST_MESSAGE_SENDER; const sender = process.env.MEDIPOST_MESSAGE_SENDER;
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseServiceRoleKey = const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY;
if ( if (
!baseUrl || !baseUrl ||
@@ -68,7 +67,7 @@ async function syncData() {
} }
: {}; : {};
const { data } = await axios.get(baseUrl, { const { data, status } = await axios.get(baseUrl, {
params: { params: {
Action: 'GetPublicMessageList', Action: 'GetPublicMessageList',
User: user, User: user,
@@ -79,11 +78,16 @@ async function syncData() {
}, },
}); });
if (!data || status !== 200) {
console.error("Failed to get public message list, status: ", status, data);
throw new Error('Failed to get public message list');
}
if (data.code && data.code !== 0) { if (data.code && data.code !== 0) {
throw new Error('Failed to get public message list'); throw new Error('Failed to get public message list');
} }
if (!data.messages.length) { if (!data.messages?.length) {
return supabase.schema('audit').from('sync_entries').insert({ return supabase.schema('audit').from('sync_entries').insert({
operation: 'ANALYSES_SYNC', operation: 'ANALYSES_SYNC',
comment: 'No new data received', comment: 'No new data received',

View File

@@ -12,8 +12,7 @@ async function syncData() {
const baseUrl = process.env.CONNECTED_ONLINE_URL; const baseUrl = process.env.CONNECTED_ONLINE_URL;
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseServiceRoleKey = const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY;
if (!baseUrl || !supabaseUrl || !supabaseServiceRoleKey) { if (!baseUrl || !supabaseUrl || !supabaseServiceRoleKey) {
throw new Error('Could not access all necessary environment variables'); throw new Error('Could not access all necessary environment variables');

View File

@@ -18,7 +18,7 @@ export default async function logRequestResult(
) { ) {
const supabaseServiceUser = createClient( const supabaseServiceUser = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, process.env.SUPABASE_SERVICE_ROLE_KEY!,
{ {
auth: { auth: {
persistSession: false, persistSession: false,

View File

@@ -331,7 +331,7 @@ export async function syncPublicMessage(
) { ) {
const supabase = createCustomClient( const supabase = createCustomClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, process.env.SUPABASE_SERVICE_ROLE_KEY!,
{ {
auth: { auth: {
persistSession: false, persistSession: false,
@@ -386,7 +386,7 @@ export async function composeOrderXML(
) { ) {
const supabase = createCustomClient( const supabase = createCustomClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, process.env.SUPABASE_SERVICE_ROLE_KEY!,
{ {
auth: { auth: {
persistSession: false, persistSession: false,
@@ -539,7 +539,7 @@ export async function syncPrivateMessage(
) { ) {
const supabase = createCustomClient( const supabase = createCustomClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, process.env.SUPABASE_SERVICE_ROLE_KEY!,
{ {
auth: { auth: {
persistSession: false, persistSession: false,

View File

@@ -8,14 +8,14 @@ import { StoreCartLineItem, StoreProductVariant } from '@medusajs/types';
import { MontonioOrderHandlerService } from '@/packages/billing/montonio/src'; import { MontonioOrderHandlerService } from '@/packages/billing/montonio/src';
import { requireUserInServerComponent } from '../server/require-user-in-server-component'; import { requireUserInServerComponent } from '../server/require-user-in-server-component';
const medusaBackendUrl = process.env.MEDUSA_BACKEND_URL!; const medusaBackendPublicUrl = process.env.MEDUSA_BACKEND_PUBLIC_URL!;
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL!; const siteUrl = process.env.NEXT_PUBLIC_SITE_URL!;
const env = z const env = z
.object({ .object({
medusaBackendUrl: z medusaBackendPublicUrl: z
.string({ .string({
required_error: 'MEDUSA_BACKEND_URL is required', required_error: 'MEDUSA_BACKEND_PUBLIC_URL is required',
}) })
.min(1), .min(1),
siteUrl: z siteUrl: z
@@ -25,7 +25,7 @@ const env = z
.min(1), .min(1),
}) })
.parse({ .parse({
medusaBackendUrl, medusaBackendPublicUrl,
siteUrl, siteUrl,
}); });
@@ -81,7 +81,7 @@ export async function handleNavigateToPayment({ language, paymentSessionId }: {
} }
const paymentLink = await new MontonioOrderHandlerService().getMontonioPaymentLink({ const paymentLink = await new MontonioOrderHandlerService().getMontonioPaymentLink({
notificationUrl: `${env.medusaBackendUrl}/api/billing/webhook`, notificationUrl: `${env.medusaBackendPublicUrl}/hooks/payment/montonio_montonio`,
returnUrl: `${env.siteUrl}/home/cart/montonio-callback`, returnUrl: `${env.siteUrl}/home/cart/montonio-callback`,
amount: cart.total, amount: cart.total,
currency: cart.currency_code.toUpperCase(), currency: cart.currency_code.toUpperCase(),

View File

@@ -34,18 +34,20 @@ import {
import { Spinner } from '@kit/ui/spinner'; import { Spinner } from '@kit/ui/spinner';
import { Trans } from '@kit/ui/trans'; import { Trans } from '@kit/ui/trans';
import pathsConfig from '~/config/paths.config';
export function MultiFactorChallengeContainer({ export function MultiFactorChallengeContainer({
paths,
userId, userId,
}: React.PropsWithChildren<{ }: React.PropsWithChildren<{
userId: string; userId: string;
paths: {
redirectPath: string;
};
}>) { }>) {
const router = useRouter(); const router = useRouter();
const verifyMFAChallenge = useVerifyMFAChallenge({ const verifyMFAChallenge = useVerifyMFAChallenge({
onSuccess: () => { onSuccess: () => {
router.replace(pathsConfig.app.home); router.replace(paths.redirectPath);
}, },
}); });

View File

@@ -114,12 +114,23 @@ export async function middleware(request: NextRequest) {
let cacheId = cacheIdCookie?.value || crypto.randomUUID(); let cacheId = cacheIdCookie?.value || crypto.randomUUID();
const regionMap = await getRegionMap(cacheId); let regionMap;
try {
regionMap = await getRegionMap(cacheId);
} catch (error) {
console.error("Error fetching regions", error);
return {
redirect: {
destination: '/auth/sign-in',
permanent: false,
},
};
}
const countryCode = regionMap && (await getCountryCode(request, regionMap)); const countryCode = regionMap && (await getCountryCode(request, regionMap));
const urlHasCountryCode = const urlHasCountryCode =
countryCode && request.nextUrl.pathname.split("/")[1].includes(countryCode); countryCode && request.nextUrl.pathname.split("/")[1]?.includes(countryCode);
// if one of the country codes is in the url and the cache id is set, return next // if one of the country codes is in the url and the cache id is set, return next
if (urlHasCountryCode && cacheIdCookie) { if (urlHasCountryCode && cacheIdCookie) {