Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 151 additions & 53 deletions README.md

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions apps/nextapp/app/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function Home() {
'x-only-raw-analysis': '1',
};

initialize({ params, headers }, (initialized) => {
initialize({ params, headers }, initialized => {
const error = initialized.error;

setIsInitialized(initialized.isSuccess);
Expand All @@ -54,7 +54,7 @@ export function Home() {
};

const onDispose = (): void => {
dispose((disposed) => {
dispose(disposed => {
setIsInitialized(!disposed);

if (!disposed) {
Expand All @@ -63,31 +63,31 @@ export function Home() {
});
};

const onLocale = async (): Promise<void> => {
const locales = LOCALES.filter((loc) => loc !== i18n);
const onLocale = (): void => {
const locales = LOCALES.filter(loc => loc !== i18n);
const newLocale = locales[Math.floor(Math.random() * locales.length)];

setI18n(newLocale);
await setLocale(newLocale);
setLocale(newLocale);
};

const onFaceScan = (type: FaceType): void => {
const onFaceScan = async (type: FaceType): Promise<void> => {
try {
switch (type) {
case 'enroll':
enroll();
await enroll();
break;
case 'authenticate':
authenticate();
await authenticate();
break;
case 'liveness':
liveness();
await liveness();
break;
case 'photoMatch':
photoMatch();
await photoMatch();
break;
case 'photoScan':
photoScan();
await photoScan();
break;
default:
toast.error(`Invalid face scan type: ${type}`);
Expand Down
3 changes: 1 addition & 2 deletions apps/nextapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"eslint": "^9",
"eslint-config-next": "16.1.7",
"tailwindcss": "^4",
"typescript": "5",
"@azify/aziface-web": "1.0.6"
"typescript": "5"
}
}
2 changes: 2 additions & 0 deletions apps/viteapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useUser } from './hooks';
import { Unless, When } from 'react-if';
import { Home } from './screens/home';
import { Login } from './screens/login';

function App() {
const { tokenBiometric, token } = useUser();
const isAuth = !!token && !!tokenBiometric;
Expand All @@ -18,4 +19,5 @@ function App() {
</QueryClientProvider>
);
}

export default App;
2 changes: 1 addition & 1 deletion apps/viteapp/src/hooks/useuser.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface UseUserProps {

export const useUserStore = create<UseUserProps>()(
persist(
(set) => ({
set => ({
token: '',
tokenBiometric: '',
setToken: (token: string) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/viteapp/src/index.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@import "tailwindcss";
@import 'tailwindcss';
9 changes: 4 additions & 5 deletions apps/viteapp/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.tsx';

createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
);
33 changes: 18 additions & 15 deletions apps/viteapp/src/screens/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import toast, { Toaster } from 'react-hot-toast';
import { useBiometricConfigs } from '../services';
import { useUser } from '../hooks';
import {
Expand Down Expand Up @@ -38,66 +39,68 @@ export function Home() {
'x-only-raw-analysis': '1',
};

initialize({ params, headers }, (initialized) => {
initialize({ params, headers }, initialized => {
const error = initialized.error;

setIsInitialized(initialized.isSuccess);
if (error) {
alert(`(${error.code}) - ${error.cause}`);
toast.error(`(${error.code}) - ${error.cause}`);
} else {
setLocale(i18n);
}
});
};

const onDispose = (): void => {
dispose((disposed) => {
dispose(disposed => {
setIsInitialized(!disposed);

if (!disposed) {
alert('Failed to dispose SDK.');
toast.error('Failed to dispose SDK.');
}
});
};

const onLocale = async (): Promise<void> => {
const locales = LOCALES.filter((loc) => loc !== i18n);
const onLocale = (): void => {
const locales = LOCALES.filter(loc => loc !== i18n);
const newLocale = locales[Math.floor(Math.random() * locales.length)];

setI18n(newLocale);
await setLocale(newLocale);
setLocale(newLocale);
};

const onFaceScan = (type: FaceType): void => {
const onFaceScan = async (type: FaceType): Promise<void> => {
try {
switch (type) {
case 'enroll':
enroll();
await enroll();
break;
case 'authenticate':
authenticate();
await authenticate();
break;
case 'liveness':
liveness();
await liveness();
break;
case 'photoMatch':
photoMatch();
await photoMatch();
break;
case 'photoScan':
photoScan();
await photoScan();
break;
default:
alert(`Invalid face scan type: ${type}`);
toast.error(`Invalid face scan type: ${type}`);
break;
}
} catch (error) {
const sessionError = error as SessionError;
alert(sessionError.message);
toast.error(sessionError.message);
}
};

return (
<div className='min-h-screen flex items-center justify-center bg-gray-50'>
<Toaster position='bottom-right' />

<div className='w-full p-5 sm:bg-white sm:border sm:border-gray-200 sm:rounded-xl sm:p-8 sm:max-w-sm sm:shadow-sm'>
<h1 className='text-2xl font-semibold text-gray-900 mb-1'>Home</h1>
<p className='text-sm text-gray-500 mb-6'>Selecione uma ação</p>
Expand Down
7 changes: 4 additions & 3 deletions apps/viteapp/src/screens/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export function Login() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const { mutateAsync: login, isPending: isPendingLogin } = useLogin();
const { mutateAsync: createSession, isPending: isPendingSession } = useBiometricSession();
const { mutateAsync: createSession, isPending: isPendingSession } =
useBiometricSession();

const handleLogin = async () => {
try {
Expand All @@ -29,7 +30,7 @@ export function Login() {
<input
type='text'
value={username}
onChange={(e) => setUsername(e.target.value)}
onChange={e => setUsername(e.target.value)}
placeholder='seu.usuario'
className='w-full border border-gray-200 rounded-lg px-3 py-2 text-sm text-gray-900 placeholder-gray-400 outline-none focus:ring-2 focus:ring-gray-300'
/>
Expand All @@ -40,7 +41,7 @@ export function Login() {
<input
type='password'
value={password}
onChange={(e) => setPassword(e.target.value)}
onChange={e => setPassword(e.target.value)}
placeholder='••••••••'
className='w-full border border-gray-200 rounded-lg px-3 py-2 text-sm text-gray-900 placeholder-gray-400 outline-none focus:ring-2 focus:ring-gray-300'
/>
Expand Down
10 changes: 5 additions & 5 deletions apps/viteapp/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const clientApi = axios.create({
});

clientApi.interceptors.request.use(
async (config) => {
async config => {
const token = useUserStore.getState()?.token || '';
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
config.validateStatus = (status) => {
config.validateStatus = status => {
if (status === 401) {
alert('Session expired. Please log in again.');
useUserStore.getState().logout();
Expand All @@ -28,12 +28,12 @@ clientApi.interceptors.request.use(
};
return config;
},
(error) => Promise.reject(error),
error => Promise.reject(error),
);

clientApi.interceptors.response.use(
(res) => res,
(error) => Promise.reject(error),
res => res,
error => Promise.reject(error),
);
export const queryClient = new QueryClient({
defaultOptions: {
Expand Down
11 changes: 9 additions & 2 deletions apps/viteapp/src/services/client.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ConfigsResponseData, CreateUserRequest, LoginRequest, LoginResponse } from '../types/services.types';
import type {
ConfigsResponseData,
CreateUserRequest,
LoginRequest,
LoginResponse,
} from '../types/services.types';
import { clientApi } from './api';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useUserStore } from '../hooks';
Expand Down Expand Up @@ -48,7 +53,9 @@ export function useBiometricConfigs() {
return useQuery({
queryKey: ['configs'],
queryFn: async () => {
const response = await clientApi.get<ConfigsResponseData>('/biometrics/configs');
const response = await clientApi.get<ConfigsResponseData>(
'/biometrics/configs',
);

return response.data;
},
Expand Down
Loading
Loading