All files / lib/components/pages/Pass index.tsx

0% Statements 0/28
0% Branches 0/6
0% Functions 0/5
0% Lines 0/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                                                                                                                   
'use client';
 
import getNiceToken, { NiceToken } from '@lib/apis/temp/getNiceToken';
import { useSearchParams } from 'next/navigation';
import React from 'react';
 
export default function PassAuthPage() {
  const searchParams = useSearchParams();
  const accessToken = searchParams.get('accessToken');
  const formRef = React.useRef<HTMLFormElement>(null);
 
  if (!accessToken) {
    throw new Error('accessToken is required');
  }
 
  const getToken = async (accessToken: string) => {
    try {
      const { data } = await getNiceToken(accessToken);
 
      return data;
    } catch (e) {
      console.error(e);
 
      throw e;
    }
  };
 
  const callNiceAuthPopup = async (niceTokenData: NiceToken) => {
    if (!formRef.current) return;
 
    formRef.current.token_version_id.value = niceTokenData.tokenVersionId;
    formRef.current.enc_data.value = niceTokenData.encData;
    formRef.current.integrity_value.value = `${niceTokenData.integrityValue}`;
    formRef.current.submit();
  };
 
  const initNiceAuth = async () => {
    try {
      const data = await getToken(accessToken);
      if (data) {
        callNiceAuthPopup(data);
      }
    } catch (e) {
      console.error(e);
    }
  };
 
  React.useEffect(() => {
    initNiceAuth();
  }, []);
 
  return (
    <form
      ref={formRef}
      name="form"
      id="form"
      action="https://nice.checkplus.co.kr/CheckPlusSafeModel/service.cb"
    >
      <input type="hidden" id="m" name="m" value="service" />
      <input type="hidden" id="token_version_id" name="token_version_id" />
      <input type="hidden" id="enc_data" name="enc_data" />
      <input type="hidden" id="integrity_value" name="integrity_value" />
    </form>
  );
}