2026-04-05 01:17:47 +02:00
|
|
|
import { useLogto } from '@logto/react';
|
2026-04-05 12:42:26 +02:00
|
|
|
import { useCallback } from 'react';
|
2026-04-05 02:50:51 +02:00
|
|
|
import { useOrgStore } from './useOrganization';
|
2026-04-05 01:17:47 +02:00
|
|
|
|
|
|
|
|
export function useAuth() {
|
2026-04-05 12:42:26 +02:00
|
|
|
const { isAuthenticated, isLoading, signOut, signIn } = useLogto();
|
2026-04-05 14:04:06 +02:00
|
|
|
const { currentTenantId } = useOrgStore();
|
2026-04-05 01:17:47 +02:00
|
|
|
|
|
|
|
|
const logout = useCallback(() => {
|
2026-04-05 23:25:53 +02:00
|
|
|
signOut(window.location.origin + '/platform/login');
|
2026-04-05 01:17:47 +02:00
|
|
|
}, [signOut]);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
isAuthenticated,
|
|
|
|
|
isLoading,
|
2026-04-05 12:42:26 +02:00
|
|
|
tenantId: currentTenantId,
|
2026-04-05 01:17:47 +02:00
|
|
|
logout,
|
|
|
|
|
signIn,
|
|
|
|
|
};
|
|
|
|
|
}
|