@opexa/portal-components 0.0.166 → 0.0.168

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/client/hooks/useAuthenticateMutation.js +7 -1
  2. package/dist/client/hooks/useCreateDigitainGameSessionMutatio.js +1 -0
  3. package/dist/client/hooks/useCreateGCashDepositMutation.js +1 -0
  4. package/dist/client/hooks/useCreateGCashWithdrawalMutation.js +1 -0
  5. package/dist/client/hooks/useCreateGameSessionMutation.js +2 -0
  6. package/dist/client/hooks/useCreateInstapayWithdrawalMutation.js +1 -0
  7. package/dist/client/hooks/useCreateMayaAppDepositMutation.js +1 -0
  8. package/dist/client/hooks/useCreateMayaAppWithdrawalMutation.js +1 -0
  9. package/dist/client/hooks/useCreateMayaDepositMutation.js +1 -0
  10. package/dist/client/hooks/useCreateMayaWithdrawalMutation.js +1 -0
  11. package/dist/client/hooks/useCreateOnlineBankDepositMutation.js +1 -0
  12. package/dist/client/hooks/useCreateQRPHDepositMutation.js +1 -0
  13. package/dist/client/hooks/useSignInMutation.js +7 -1
  14. package/dist/client/hooks/useSignUpMutation.d.ts +1 -1
  15. package/dist/client/hooks/useSignUpMutation.js +10 -1
  16. package/dist/client/services/getSession.js +3 -1
  17. package/dist/components/DepositWithdrawal/Deposit/OnlineBankDeposit/OnlineBankDepositContext.d.ts +2 -2
  18. package/dist/components/DepositWithdrawal/Deposit/OnlineBankDeposit/useOnlineBankDeposit.d.ts +1 -1
  19. package/dist/components/DepositWithdrawal/Deposit/QRPHDeposit/QRPHDepositContext.d.ts +2 -2
  20. package/dist/components/DepositWithdrawal/Deposit/QRPHDeposit/useQRPHDeposit.d.ts +1 -1
  21. package/dist/components/KYC/CaptureSelfie.js +21 -7
  22. package/dist/components/SignUp/SignUpForm.js +0 -2
  23. package/dist/constants/HeaderKey.d.ts +1 -0
  24. package/dist/constants/HeaderKey.js +1 -0
  25. package/dist/constants/StorageKey.d.ts +1 -0
  26. package/dist/constants/StorageKey.js +1 -0
  27. package/dist/handlers.d.ts +2 -8
  28. package/dist/handlers.js +14 -1
  29. package/dist/middleware.js +13 -6
  30. package/dist/server/services/getSession.js +17 -6
  31. package/dist/types/index.d.ts +2 -0
  32. package/package.json +1 -1
@@ -3,13 +3,19 @@ import { getQueryClient } from '../../utils/getQueryClient.js';
3
3
  import { getAuthenticateMutationKey } from '../../utils/mutationKeys.js';
4
4
  import { getSessionQueryKey } from '../../utils/queryKeys.js';
5
5
  import { authenticate } from '../services/authenticate.js';
6
+ import { getSession } from '../services/getSession.js';
6
7
  export const useAuthenticateMutation = (config) => {
7
8
  const queryClient = getQueryClient();
8
9
  return useMutation({
9
10
  ...config,
10
11
  mutationKey: getAuthenticateMutationKey(),
11
12
  mutationFn: async (input) => {
12
- await authenticate(input);
13
+ const session = await getSession();
14
+ await authenticate(input, {
15
+ headers: {
16
+ Domain: session.domain,
17
+ },
18
+ });
13
19
  await queryClient.invalidateQueries({
14
20
  queryKey: getSessionQueryKey(),
15
21
  });
@@ -20,6 +20,7 @@ export const useCreateDigitainGameSessionMutatio = (config) => {
20
20
  }, {
21
21
  headers: {
22
22
  Authorization: `Bearer ${session.token}`,
23
+ Domain: session.domain,
23
24
  },
24
25
  });
25
26
  const data = await createPoll(async () => {
@@ -22,6 +22,7 @@ export const useCreateGCashDepositMutation = (config) => {
22
22
  await createGCashDeposit({ ...input, id }, {
23
23
  headers: {
24
24
  Authorization: `Bearer ${session.token}`,
25
+ Domain: session.domain,
25
26
  },
26
27
  });
27
28
  const poll = createPoll(async () => {
@@ -16,6 +16,7 @@ export const useCreateGCashWithdrawalMutation = (config) => {
16
16
  await createGCashWithdrawal({ ...input, id }, {
17
17
  headers: {
18
18
  Authorization: `Bearer ${session.token}`,
19
+ Domain: session.domain,
19
20
  },
20
21
  });
21
22
  return id;
@@ -22,6 +22,7 @@ export const useCreateGameSessionMutation = (config) => {
22
22
  game: 'reference' in game ? game.reference : game.id,
23
23
  }, {
24
24
  headers: {
25
+ Domain: session.domain,
25
26
  Authorization: `Bearer ${session.token}`,
26
27
  },
27
28
  });
@@ -53,6 +54,7 @@ export const useCreateGameSessionMutation = (config) => {
53
54
  }, {
54
55
  headers: {
55
56
  Authorization: `Bearer ${session.token}`,
57
+ Domain: session.domain,
56
58
  },
57
59
  });
58
60
  const data = await createPoll(async () => {
@@ -16,6 +16,7 @@ export const useCreateInstapayWithdrawalMutation = (config) => {
16
16
  await createAIOInstapayWithdrawal({ ...input, id }, {
17
17
  headers: {
18
18
  Authorization: `Bearer ${session.token}`,
19
+ Domain: session.domain,
19
20
  },
20
21
  });
21
22
  return id;
@@ -30,6 +30,7 @@ export const useCreateMayaAppDepositMutation = (config) => {
30
30
  return await getDeposit(id, {
31
31
  headers: {
32
32
  Authorization: `Bearer ${session.token}`,
33
+ Domain: session.domain,
33
34
  },
34
35
  });
35
36
  }, {
@@ -16,6 +16,7 @@ export const useCreateMayaAppWithdrawalMutation = (config) => {
16
16
  await createMayaAppWithdrawal({ ...input, id }, {
17
17
  headers: {
18
18
  Authorization: `Bearer ${session.token}`,
19
+ Domain: session.domain,
19
20
  },
20
21
  });
21
22
  return id;
@@ -22,6 +22,7 @@ export const useCreateMayaDepositMutation = (config) => {
22
22
  await createMayaDeposit({ ...input, id }, {
23
23
  headers: {
24
24
  Authorization: `Bearer ${session.token}`,
25
+ Domain: session.domain,
25
26
  },
26
27
  });
27
28
  const poll = createPoll(async () => {
@@ -16,6 +16,7 @@ export const useCreateMayaWithdrawalMutation = (config) => {
16
16
  await createMayaWithdrawal({ ...input, id }, {
17
17
  headers: {
18
18
  Authorization: `Bearer ${session.token}`,
19
+ Domain: session.domain,
19
20
  },
20
21
  });
21
22
  return id;
@@ -22,6 +22,7 @@ export const useCreateOnlineBankDepositMutation = (config) => {
22
22
  await createAIOOnlineBankDeposit({ ...input, id }, {
23
23
  headers: {
24
24
  Authorization: `Bearer ${session.token}`,
25
+ Domain: session.domain,
25
26
  },
26
27
  });
27
28
  const poll = createPoll(async () => {
@@ -22,6 +22,7 @@ export const useCreateQRPHDepositMutation = (config) => {
22
22
  await createAIOQRPHDeposit({ ...input, id }, {
23
23
  headers: {
24
24
  Authorization: `Bearer ${session.token}`,
25
+ Domain: session.domain,
25
26
  },
26
27
  });
27
28
  const poll = createPoll(async () => {
@@ -2,6 +2,7 @@ import { useMutation } from '@tanstack/react-query';
2
2
  import { getQueryClient } from '../../utils/getQueryClient.js';
3
3
  import { getSignInMutationKey } from '../../utils/mutationKeys.js';
4
4
  import { getSessionQueryKey } from '../../utils/queryKeys.js';
5
+ import { getSession } from '../services/getSession.js';
5
6
  import { signIn } from '../services/signIn.js';
6
7
  export const useSignInMutation = (config) => {
7
8
  const queryClient = getQueryClient();
@@ -9,7 +10,12 @@ export const useSignInMutation = (config) => {
9
10
  ...config,
10
11
  mutationKey: getSignInMutationKey(),
11
12
  mutationFn: async (input) => {
12
- const authenticator = await signIn(input);
13
+ const session = await getSession();
14
+ const authenticator = await signIn(input, {
15
+ headers: {
16
+ Domain: session.domain,
17
+ },
18
+ });
13
19
  if (!authenticator) {
14
20
  await queryClient.invalidateQueries({
15
21
  queryKey: getSessionQueryKey(),
@@ -1,5 +1,5 @@
1
1
  import { type RegisterMemberAccountViaMobileInput } from '../../services/account';
2
2
  import type { Mutation } from '../../types';
3
- export interface SignUpMutationInput extends RegisterMemberAccountViaMobileInput {
3
+ export interface SignUpMutationInput extends Omit<RegisterMemberAccountViaMobileInput, 'domain'> {
4
4
  }
5
5
  export declare const useSignUpMutation: Mutation<void, SignUpMutationInput>;
@@ -1,12 +1,21 @@
1
1
  import { useMutation } from '@tanstack/react-query';
2
2
  import { registerMemberAccountViaMobile, } from '../../services/account.js';
3
3
  import { getSignUpMutationKey } from '../../utils/mutationKeys.js';
4
+ import { getSession } from '../services/getSession.js';
4
5
  export const useSignUpMutation = (config) => {
5
6
  return useMutation({
6
7
  ...config,
7
8
  mutationKey: getSignUpMutationKey(),
8
9
  mutationFn: async (input) => {
9
- return await registerMemberAccountViaMobile(input);
10
+ const { domain } = await getSession();
11
+ return await registerMemberAccountViaMobile({
12
+ domain,
13
+ ...input,
14
+ }, {
15
+ headers: {
16
+ domain,
17
+ },
18
+ });
10
19
  },
11
20
  });
12
21
  };
@@ -2,5 +2,7 @@ import { cache } from 'react';
2
2
  import { httpRequest, } from '../../services/httpRequest.js';
3
3
  export const getSession = cache(async (options) => {
4
4
  const res = await httpRequest.json('/api/sessions', options);
5
- return res.ok ? res.data : { status: 'unauthenticated' };
5
+ return res.ok
6
+ ? res.data
7
+ : { status: 'unauthenticated', domain: window.location.origin };
6
8
  });
@@ -1,6 +1,6 @@
1
1
  export declare const OnlineBankDepositContext: (props: {
2
2
  value: {
3
- view: "form" | "vca";
3
+ view: "vca" | "form";
4
4
  status: "waiting" | "processing" | "failed" | "verification-waiting" | "verification-processing" | "verification-failed" | "verification-success";
5
5
  verify: () => void;
6
6
  reset: () => void;
@@ -13,7 +13,7 @@ export declare const OnlineBankDepositContext: (props: {
13
13
  } & {
14
14
  children?: import("react").ReactNode | undefined;
15
15
  }) => React.ReactNode, useOnlineBankDepositContext: () => {
16
- view: "form" | "vca";
16
+ view: "vca" | "form";
17
17
  status: "waiting" | "processing" | "failed" | "verification-waiting" | "verification-processing" | "verification-failed" | "verification-success";
18
18
  verify: () => void;
19
19
  reset: () => void;
@@ -1,7 +1,7 @@
1
1
  import type { Deposit } from '../../../../types';
2
2
  export type UseOnlineBankDepositReturn = ReturnType<typeof useOnlineBankDeposit>;
3
3
  export declare function useOnlineBankDeposit(): {
4
- view: "form" | "vca";
4
+ view: "vca" | "form";
5
5
  status: "waiting" | "processing" | "failed" | "verification-waiting" | "verification-processing" | "verification-failed" | "verification-success";
6
6
  verify: () => void;
7
7
  reset: () => void;
@@ -1,6 +1,6 @@
1
1
  export declare const QRPHDepositContext: (props: {
2
2
  value: {
3
- view: "form" | "qrCode";
3
+ view: "qrCode" | "form";
4
4
  status: "waiting" | "processing" | "failed" | "verification-waiting" | "verification-processing" | "verification-failed" | "verification-success";
5
5
  verify: () => void;
6
6
  reset: () => void;
@@ -13,7 +13,7 @@ export declare const QRPHDepositContext: (props: {
13
13
  } & {
14
14
  children?: import("react").ReactNode | undefined;
15
15
  }) => React.ReactNode, useQRPHDepositContext: () => {
16
- view: "form" | "qrCode";
16
+ view: "qrCode" | "form";
17
17
  status: "waiting" | "processing" | "failed" | "verification-waiting" | "verification-processing" | "verification-failed" | "verification-success";
18
18
  verify: () => void;
19
19
  reset: () => void;
@@ -1,7 +1,7 @@
1
1
  import type { Deposit } from '../../../../types';
2
2
  export type UseQRPHDepositReturn = ReturnType<typeof useQRPHDeposit>;
3
3
  export declare function useQRPHDeposit(): {
4
- view: "form" | "qrCode";
4
+ view: "qrCode" | "form";
5
5
  status: "waiting" | "processing" | "failed" | "verification-waiting" | "verification-processing" | "verification-failed" | "verification-success";
6
6
  verify: () => void;
7
7
  reset: () => void;
@@ -22,6 +22,7 @@ export function CaptureSelfie() {
22
22
  const [captureInProgress, setCaptureInProgress] = useState(false);
23
23
  const [selectedImage, setSelectedImage] = useState(null);
24
24
  const [isFaceCentered, setIsFaceCentered] = useState(false);
25
+ const [isCapturing, setIsCapturing] = useState(false);
25
26
  const [countdown, setCountdown] = useState(3);
26
27
  const videoRef = useRef(null);
27
28
  const faceCanvasRef = useRef(null);
@@ -113,15 +114,27 @@ export function CaptureSelfie() {
113
114
  Math.abs(faceCenterY - screenCenterY) <= centerThresholdY;
114
115
  setIsFaceCentered(isFaceCentered);
115
116
  const faceDetectionConfidence = detection.detection.score * 100;
116
- const context = faceCanvasRef.current.getContext('2d');
117
- if (context) {
118
- context.clearRect(0, 0, faceCanvasRef.current.width, faceCanvasRef.current.height);
119
- faceapi.draw.drawDetections(faceCanvasRef.current, resizedDetection);
120
- faceapi.draw.drawFaceLandmarks(faceCanvasRef.current, resizedDetection);
121
- }
117
+ // const context = faceCanvasRef.current.getContext('2d');
118
+ // if (context) {
119
+ // context.clearRect(
120
+ // 0,
121
+ // 0,
122
+ // faceCanvasRef.current.width,
123
+ // faceCanvasRef.current.height,
124
+ // );
125
+ // faceapi.draw.drawDetections(
126
+ // faceCanvasRef.current,
127
+ // resizedDetection,
128
+ // );
129
+ // faceapi.draw.drawFaceLandmarks(
130
+ // faceCanvasRef.current,
131
+ // resizedDetection,
132
+ // );
133
+ // }
122
134
  //adjust the faceDetectionConfidence if need
123
135
  if (isFaceCentered && faceDetectionConfidence >= 65) {
124
136
  if (!countdownInterval) {
137
+ setIsCapturing(true);
125
138
  countdownInterval = setInterval(() => {
126
139
  setCountdown((prev) => {
127
140
  if (prev === 1) {
@@ -140,6 +153,7 @@ export function CaptureSelfie() {
140
153
  clearInterval(countdownInterval);
141
154
  countdownInterval = null;
142
155
  setCountdown(3);
156
+ setIsCapturing(false);
143
157
  }
144
158
  }
145
159
  }
@@ -233,5 +247,5 @@ export function CaptureSelfie() {
233
247
  return (_jsxs("div", { className: "w-full p-4 lg:w-[640px] lg:px-12 lg:py-4xl", children: [_jsxs("button", { type: "button", className: "flex items-center gap-lg lg:absolute lg:right-5 lg:top-5 lg:p-md", onClick: () => {
234
248
  stopCamera();
235
249
  kyc.setCapturing(null);
236
- }, children: [_jsx(XIcon, { className: "text-text-senary-300 hidden size-5 lg:block" }), _jsx(ArrowLeftIcon, { className: "text-text-senary-300 size-5 lg:hidden" }), _jsx("span", { className: "text-lg font-semibold lg:hidden", children: "Back" })] }), _jsx(Dialog.Title, { className: "mt-6 text-center text-lg font-semibold lg:mt-0", children: "Take a Selfie Holding Your ID" }), _jsx(Dialog.Description, { className: "text-text-tertiary-600 mx-auto mt-sm max-w-[19rem] text-center text-sm lg:max-w-full", children: "Make sure your face and ID are clearly visible, with no glare or blur." }), _jsx("div", { id: "parent", className: "border-border-disabled mt-6 aspect-video rounded-xl border bg-black lg:mt-8", children: captureInProgress ? (_jsxs("div", { className: "relative flex h-fit w-full flex-col items-center justify-center", children: [_jsx("video", { ref: videoRef, autoPlay: true, muted: true, className: "h-[60vh] w-full rounded-lg object-cover md:aspect-video md:h-[333px]", width: "100%", height: "100%" }), _jsx("canvas", { ref: faceCanvasRef, className: "absolute inset-0 h-[60vh] w-full object-cover md:aspect-video md:h-[333px] md:object-contain", width: "100%", height: "100%" }), isFaceCentered && (_jsx("span", { className: "absolute inset-x-0 bottom-8 flex items-center justify-center text-5xl font-bold text-[#713B12CC] md:bottom-4", children: countdown })), !isFaceCentered && (_jsx("span", { className: "absolute inset-x-0 bottom-12 mx-auto w-1/2 text-center text-xs text-white md:bottom-3", children: "Please center your face in the camera view. Make sure your ID is clearly visible next to your face." })), _jsx(PersonOverlayDesktop, { isFaceCentered: isFaceCentered, width: videoRef.current?.clientWidth || 543, height: videoRef.current?.clientHeight || 333 })] })) : (selectedImage && (_jsx("img", { src: selectedImage, alt: "Captured Photo", className: "h-full w-full rounded-lg object-cover md:aspect-video md:h-[333px]" }))) }), selectedImage && (_jsxs("div", { className: "flex flex-col items-center justify-center gap-2 md:flex-row", children: [_jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: retakePhoto, type: "button", children: ["Rekate Photo", _jsx(Camera01Icon, { className: "size-5" })] }), _jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: usePhoto, type: "button", disabled: isPending, children: ["Use Photo", _jsx(Camera01Icon, { className: "size-5" })] })] })), !selectedImage && (_jsxs(Button, { className: "mx-auto mt-6 px-xl lg:mt-8", onClick: startCamera, disabled: !modelsLoaded, type: "button", children: ["Start Camera", _jsx(Camera01Icon, { className: "size-5" })] }))] }));
250
+ }, children: [_jsx(XIcon, { className: "text-text-senary-300 hidden size-5 lg:block" }), _jsx(ArrowLeftIcon, { className: "text-text-senary-300 size-5 lg:hidden" }), _jsx("span", { className: "text-lg font-semibold lg:hidden", children: "Back" })] }), _jsx(Dialog.Title, { className: "mt-6 text-center text-lg font-semibold lg:mt-0", children: "Take a Selfie Holding Your ID" }), _jsx(Dialog.Description, { className: "text-text-tertiary-600 mx-auto mt-sm max-w-[19rem] text-center text-sm lg:max-w-full", children: "Make sure your face and ID are clearly visible, with no glare or blur." }), _jsx("div", { id: "parent", className: "border-border-disabled mt-6 aspect-video rounded-xl border bg-black lg:mt-8", children: captureInProgress ? (_jsxs("div", { className: "relative flex h-fit w-full flex-col items-center justify-center", children: [_jsx("video", { ref: videoRef, autoPlay: true, muted: true, className: "h-[60vh] w-full rounded-lg object-cover md:aspect-video md:h-[333px]", width: "100%", height: "100%" }), _jsx("canvas", { ref: faceCanvasRef, className: "absolute inset-0 h-[60vh] w-full object-cover md:aspect-video md:h-[333px] md:object-contain", width: "100%", height: "100%" }), isCapturing && (_jsx("span", { className: "absolute inset-x-0 bottom-8 flex items-center justify-center text-5xl font-bold text-[#713B12CC] md:bottom-4", children: countdown })), !isFaceCentered && (_jsx("span", { className: "absolute inset-x-0 bottom-12 mx-auto w-1/2 text-center text-xs text-white md:bottom-3", children: "Please center your face in the camera view. Make sure your ID is clearly visible next to your face." })), _jsx(PersonOverlayDesktop, { isFaceCentered: isFaceCentered, width: videoRef.current?.clientWidth || 543, height: videoRef.current?.clientHeight || 333 })] })) : (selectedImage && (_jsx("img", { src: selectedImage, alt: "Captured Photo", className: "h-full w-full rounded-lg object-cover md:aspect-video md:h-[333px]" }))) }), selectedImage && (_jsxs("div", { className: "flex flex-col items-center justify-center gap-2 md:flex-row", children: [_jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: retakePhoto, type: "button", children: ["Rekate Photo", _jsx(Camera01Icon, { className: "size-5" })] }), _jsxs(Button, { className: "disabled:bg-bg-disabled disabled:text-text-disabled mx-auto mt-4 px-xl disabled:opacity-100", size: "sm", onClick: usePhoto, type: "button", disabled: isPending, children: ["Use Photo", _jsx(Camera01Icon, { className: "size-5" })] })] })), !selectedImage && (_jsxs(Button, { className: "mx-auto mt-6 px-xl lg:mt-8", onClick: startCamera, disabled: !modelsLoaded, type: "button", children: ["Start Camera", _jsx(Camera01Icon, { className: "size-5" })] }))] }));
237
251
  }
@@ -192,8 +192,6 @@ export function SignUpForm() {
192
192
  mobileNumber: mobileNumberParser.format(mobileNumber),
193
193
  verificationCode: verificationCode.join(''),
194
194
  referralCode: search.get('referralCode') ?? undefined,
195
- domain: search.get('domain') ??
196
- new URL(window.location.href).hostname,
197
195
  btag: search.get('btag') ?? undefined,
198
196
  });
199
197
  const name = mobileNumberParser.format(mobileNumber);
@@ -1,2 +1,3 @@
1
1
  export declare const RECAPTCHA_HEADER_KEY: string;
2
2
  export declare const TEST_PASS_HEADER_KEY: string;
3
+ export declare const DOMAIN_HEADER_KEY: string;
@@ -1,2 +1,3 @@
1
1
  export const RECAPTCHA_HEADER_KEY = 'Google-Recaptcha-Response';
2
2
  export const TEST_PASS_HEADER_KEY = 'Test-Pass';
3
+ export const DOMAIN_HEADER_KEY = 'Domain';
@@ -1,3 +1,4 @@
1
1
  export declare const ACCESS_TOKEN_COOKIE_NAME: string;
2
2
  export declare const REFRESH_TOKEN_COOKIE_NAME: string;
3
3
  export declare const KYC_PROMPT_LOCALSTORAGE_KEY: string;
4
+ export declare const DOMAIN_COOKIE_NAME: string;
@@ -1,3 +1,4 @@
1
1
  export const ACCESS_TOKEN_COOKIE_NAME = 'WebPortalAuthAccessToken';
2
2
  export const REFRESH_TOKEN_COOKIE_NAME = 'WebPortalAuthRefreshToken';
3
3
  export const KYC_PROMPT_LOCALSTORAGE_KEY = 'WebPortalKYCPrompted';
4
+ export const DOMAIN_COOKIE_NAME = 'WebPortalDomain';
@@ -1,10 +1,5 @@
1
1
  import { NextResponse, type NextRequest } from 'next/server';
2
- type GetSessionResponse = {
3
- status: 'authenticated';
4
- token: string;
5
- } | {
6
- status: 'unauthenticated';
7
- };
2
+ import type { Session } from './types';
8
3
  export declare const GET: (request: NextRequest, { params }: {
9
4
  params: Promise<{
10
5
  auth: string[];
@@ -22,7 +17,7 @@ export declare const GET: (request: NextRequest, { params }: {
22
17
  __error?: unknown;
23
18
  } | {
24
19
  ok: true;
25
- data: GetSessionResponse;
20
+ data: Session;
26
21
  }>>;
27
22
  export declare const DELETE: (request: NextRequest, { params }: {
28
23
  params: Promise<{
@@ -41,4 +36,3 @@ export declare const POST: (request: NextRequest, { params }: {
41
36
  auth: string[];
42
37
  }>;
43
38
  }) => Promise<NextResponse>;
44
- export {};
package/dist/handlers.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { addDays, addMinutes, subMinutes } from 'date-fns';
2
2
  import { NextResponse } from 'next/server';
3
3
  import { z } from 'zod';
4
- import { ACCESS_TOKEN_COOKIE_NAME, PLATFORM_CODE, RECAPTCHA_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, } from './constants/index.js';
4
+ import { ACCESS_TOKEN_COOKIE_NAME, DOMAIN_COOKIE_NAME, DOMAIN_HEADER_KEY, PLATFORM_CODE, RECAPTCHA_HEADER_KEY, REFRESH_TOKEN_COOKIE_NAME, } from './constants/index.js';
5
5
  import { authenticate, createSession, destroySession, refreshSession, } from './services/auth.js';
6
6
  const CreateSessionDefinition = z.union([
7
7
  z.object({
@@ -62,10 +62,12 @@ export const GET = async (request, { params }) => {
62
62
  if (path === 'sessions') {
63
63
  const accessToken = request.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
64
64
  const refreshToken = request.cookies.get(REFRESH_TOKEN_COOKIE_NAME)?.value;
65
+ const domain = request.cookies.get(DOMAIN_COOKIE_NAME)?.value ?? request.nextUrl.origin;
65
66
  if (!refreshToken) {
66
67
  const response = NextResponse.json({
67
68
  ok: true,
68
69
  data: {
70
+ domain,
69
71
  status: 'unauthenticated',
70
72
  },
71
73
  });
@@ -84,6 +86,7 @@ export const GET = async (request, { params }) => {
84
86
  ok: true,
85
87
  data: {
86
88
  status: 'authenticated',
89
+ domain,
87
90
  token: data.accessToken,
88
91
  },
89
92
  });
@@ -99,6 +102,7 @@ export const GET = async (request, { params }) => {
99
102
  ok: true,
100
103
  data: {
101
104
  status: 'unauthenticated',
105
+ domain,
102
106
  },
103
107
  });
104
108
  response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
@@ -109,6 +113,7 @@ export const GET = async (request, { params }) => {
109
113
  ok: true,
110
114
  data: {
111
115
  status: 'authenticated',
116
+ domain,
112
117
  token: accessToken,
113
118
  },
114
119
  });
@@ -159,6 +164,7 @@ export const POST = async (request, { params }) => {
159
164
  const body = await request.json();
160
165
  const parsed = CreateSessionDefinition.safeParse(body);
161
166
  const recaptcha = request.headers.get(RECAPTCHA_HEADER_KEY);
167
+ const domain = request.headers.get(DOMAIN_HEADER_KEY);
162
168
  if (!parsed.success) {
163
169
  return NextResponse.json({
164
170
  ok: false,
@@ -172,6 +178,9 @@ export const POST = async (request, { params }) => {
172
178
  ...(recaptcha && {
173
179
  [RECAPTCHA_HEADER_KEY]: recaptcha,
174
180
  }),
181
+ ...(domain && {
182
+ [DOMAIN_HEADER_KEY]: domain,
183
+ }),
175
184
  },
176
185
  });
177
186
  if (res.authenticator) {
@@ -210,6 +219,7 @@ export const POST = async (request, { params }) => {
210
219
  const body = await request.json();
211
220
  const parsed = AuthenticateDefinition.safeParse(body);
212
221
  const recaptcha = request.headers.get(RECAPTCHA_HEADER_KEY);
222
+ const domain = request.headers.get(DOMAIN_HEADER_KEY);
213
223
  if (!parsed.success) {
214
224
  return NextResponse.json({
215
225
  ok: false,
@@ -223,6 +233,9 @@ export const POST = async (request, { params }) => {
223
233
  ...(recaptcha && {
224
234
  [RECAPTCHA_HEADER_KEY]: recaptcha,
225
235
  }),
236
+ ...(domain && {
237
+ [DOMAIN_HEADER_KEY]: domain,
238
+ }),
226
239
  },
227
240
  });
228
241
  const response = NextResponse.json({ ok: true }, { status: 201 });
@@ -1,6 +1,6 @@
1
- import { addMinutes } from 'date-fns';
1
+ import { addDays, addMinutes } from 'date-fns';
2
2
  import { NextFetchEvent, NextResponse, } from 'next/server';
3
- import { ACCESS_TOKEN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from './constants/index.js';
3
+ import { ACCESS_TOKEN_COOKIE_NAME, DOMAIN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from './constants/index.js';
4
4
  import { refreshSession } from './services/auth.js';
5
5
  export const config = {
6
6
  runtime: 'nodejs',
@@ -11,7 +11,14 @@ export const config = {
11
11
  export const middleware = async (req) => {
12
12
  const accessToken = req.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
13
13
  const refreshToken = req.cookies.get(REFRESH_TOKEN_COOKIE_NAME)?.value;
14
- const response = NextResponse.next();
14
+ const res = NextResponse.next();
15
+ if (req.nextUrl.searchParams.get('m')) {
16
+ res.cookies.set(DOMAIN_COOKIE_NAME, `${req.nextUrl.origin}/${req.nextUrl.searchParams.get('m')}`, {
17
+ expires: addDays(new Date(), 30),
18
+ httpOnly: true,
19
+ sameSite: 'strict',
20
+ });
21
+ }
15
22
  if (!accessToken && refreshToken) {
16
23
  try {
17
24
  const data = await refreshSession({
@@ -19,17 +26,17 @@ export const middleware = async (req) => {
19
26
  Authorization: `Bearer ${refreshToken}`,
20
27
  },
21
28
  });
22
- response.cookies.set(ACCESS_TOKEN_COOKIE_NAME, data.accessToken, {
29
+ res.cookies.set(ACCESS_TOKEN_COOKIE_NAME, data.accessToken, {
23
30
  expires: addMinutes(new Date(), 9),
24
31
  httpOnly: true,
25
32
  sameSite: 'strict',
26
33
  });
27
34
  }
28
35
  catch {
29
- response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
36
+ res.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
30
37
  }
31
38
  }
32
- return response;
39
+ return res;
33
40
  };
34
41
  export function extendMiddleware(fn) {
35
42
  return async (req, evt) => fn(req, evt, await middleware(req));
@@ -1,10 +1,21 @@
1
- import { cookies } from 'next/headers';
1
+ import { cookies, headers } from 'next/headers';
2
2
  import { cache } from 'react';
3
- import { ACCESS_TOKEN_COOKIE_NAME } from '../../constants/index.js';
3
+ import { ACCESS_TOKEN_COOKIE_NAME, DOMAIN_COOKIE_NAME } from '../../constants/index.js';
4
4
  export const getSession = cache(async () => {
5
5
  const Cookies = await cookies();
6
- const accessToken = Cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
7
- return accessToken
8
- ? { status: 'authenticated', token: accessToken }
9
- : { status: 'unauthenticated' };
6
+ const Headers = await headers();
7
+ const token = Cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
8
+ const headerProto = Headers.get('x-forwarded-proto') ?? 'http';
9
+ const headerHost = Headers.get('x-forwarded-host') ?? 'localhost';
10
+ const domain = Cookies.get(DOMAIN_COOKIE_NAME)?.value ?? `${headerProto}://${headerHost}`;
11
+ return token
12
+ ? {
13
+ status: 'authenticated',
14
+ domain,
15
+ token,
16
+ }
17
+ : {
18
+ status: 'unauthenticated',
19
+ domain,
20
+ };
10
21
  });
@@ -7,9 +7,11 @@ import type { ImageProps } from 'next/image';
7
7
  */
8
8
  export type Session = {
9
9
  status: 'authenticated';
10
+ domain: string;
10
11
  token: string;
11
12
  } | {
12
13
  status: 'unauthenticated';
14
+ domain: string;
13
15
  token?: null;
14
16
  };
15
17
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opexa/portal-components",
3
- "version": "0.0.166",
3
+ "version": "0.0.168",
4
4
  "exports": {
5
5
  "./ui/*": {
6
6
  "types": "./dist/ui/*/index.d.ts",