diff --git a/.env b/.env index e7b866f..04c866d 100644 --- a/.env +++ b/.env @@ -69,3 +69,7 @@ NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY= NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo MONTONIO_API_URL=https://sandbox-stargate.montonio.com + +# MEDUSA +MEDUSA_BACKEND_URL=http://localhost:9000 +MEDUSA_BACKEND_PUBLIC_URL=http://localhost:9000 diff --git a/.env.example b/.env.example index 92af783..ce9f94c 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,7 @@ # https://app.supabase.com/project/_/settings/api NEXT_PUBLIC_SUPABASE_URL=your-project-url 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_USER=your-medipost-user diff --git a/app/auth/verify/page.tsx b/app/auth/verify/page.tsx index 2123611..8d275bf 100644 --- a/app/auth/verify/page.tsx +++ b/app/auth/verify/page.tsx @@ -39,7 +39,17 @@ async function VerifyPage(props: Props) { redirect(pathsConfig.auth.signIn); } - return ; + const nextPath = (await props.searchParams).next; + const redirectPath = nextPath ?? pathsConfig.app.home; + + return ( + + ); } export default withI18n(VerifyPage); diff --git a/jobs/sync-analysis-groups.ts b/jobs/sync-analysis-groups.ts index e375248..d7e32d1 100644 --- a/jobs/sync-analysis-groups.ts +++ b/jobs/sync-analysis-groups.ts @@ -30,8 +30,7 @@ async function syncData() { const password = process.env.MEDIPOST_PASSWORD; const sender = process.env.MEDIPOST_MESSAGE_SENDER; const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; - const supabaseServiceRoleKey = - process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY; + const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY; if ( !baseUrl || @@ -68,7 +67,7 @@ async function syncData() { } : {}; - const { data } = await axios.get(baseUrl, { + const { data, status } = await axios.get(baseUrl, { params: { Action: 'GetPublicMessageList', 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) { 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({ operation: 'ANALYSES_SYNC', comment: 'No new data received', diff --git a/jobs/sync-connected-online.ts b/jobs/sync-connected-online.ts index d2ad5c9..4944bb7 100644 --- a/jobs/sync-connected-online.ts +++ b/jobs/sync-connected-online.ts @@ -12,8 +12,7 @@ async function syncData() { const baseUrl = process.env.CONNECTED_ONLINE_URL; const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; - const supabaseServiceRoleKey = - process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY; + const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY; if (!baseUrl || !supabaseUrl || !supabaseServiceRoleKey) { throw new Error('Could not access all necessary environment variables'); diff --git a/lib/services/audit.service.ts b/lib/services/audit.service.ts index 994a25b..5d15548 100644 --- a/lib/services/audit.service.ts +++ b/lib/services/audit.service.ts @@ -18,7 +18,7 @@ export default async function logRequestResult( ) { const supabaseServiceUser = createClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, - process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, + process.env.SUPABASE_SERVICE_ROLE_KEY!, { auth: { persistSession: false, diff --git a/lib/services/medipost.service.ts b/lib/services/medipost.service.ts index 775f870..7e25449 100644 --- a/lib/services/medipost.service.ts +++ b/lib/services/medipost.service.ts @@ -331,7 +331,7 @@ export async function syncPublicMessage( ) { const supabase = createCustomClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, - process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, + process.env.SUPABASE_SERVICE_ROLE_KEY!, { auth: { persistSession: false, @@ -386,7 +386,7 @@ export async function composeOrderXML( ) { const supabase = createCustomClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, - process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, + process.env.SUPABASE_SERVICE_ROLE_KEY!, { auth: { persistSession: false, @@ -539,7 +539,7 @@ export async function syncPrivateMessage( ) { const supabase = createCustomClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, - process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY!, + process.env.SUPABASE_SERVICE_ROLE_KEY!, { auth: { persistSession: false, diff --git a/lib/services/medusaCart.service.ts b/lib/services/medusaCart.service.ts index 821076f..3730917 100644 --- a/lib/services/medusaCart.service.ts +++ b/lib/services/medusaCart.service.ts @@ -8,14 +8,14 @@ import { StoreCartLineItem, StoreProductVariant } from '@medusajs/types'; import { MontonioOrderHandlerService } from '@/packages/billing/montonio/src'; 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 env = z .object({ - medusaBackendUrl: z + medusaBackendPublicUrl: z .string({ - required_error: 'MEDUSA_BACKEND_URL is required', + required_error: 'MEDUSA_BACKEND_PUBLIC_URL is required', }) .min(1), siteUrl: z @@ -25,7 +25,7 @@ const env = z .min(1), }) .parse({ - medusaBackendUrl, + medusaBackendPublicUrl, siteUrl, }); @@ -81,7 +81,7 @@ export async function handleNavigateToPayment({ language, paymentSessionId }: { } 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`, amount: cart.total, currency: cart.currency_code.toUpperCase(), diff --git a/packages/features/auth/src/components/multi-factor-challenge-container.tsx b/packages/features/auth/src/components/multi-factor-challenge-container.tsx index 2de18df..a9a7fdd 100644 --- a/packages/features/auth/src/components/multi-factor-challenge-container.tsx +++ b/packages/features/auth/src/components/multi-factor-challenge-container.tsx @@ -34,18 +34,20 @@ import { import { Spinner } from '@kit/ui/spinner'; import { Trans } from '@kit/ui/trans'; -import pathsConfig from '~/config/paths.config'; - export function MultiFactorChallengeContainer({ + paths, userId, }: React.PropsWithChildren<{ userId: string; + paths: { + redirectPath: string; + }; }>) { const router = useRouter(); const verifyMFAChallenge = useVerifyMFAChallenge({ onSuccess: () => { - router.replace(pathsConfig.app.home); + router.replace(paths.redirectPath); }, }); diff --git a/packages/features/medusa-storefront/src/middleware.ts b/packages/features/medusa-storefront/src/middleware.ts index 21290da..0d59700 100644 --- a/packages/features/medusa-storefront/src/middleware.ts +++ b/packages/features/medusa-storefront/src/middleware.ts @@ -114,12 +114,23 @@ export async function middleware(request: NextRequest) { 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 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 (urlHasCountryCode && cacheIdCookie) {