소스 정보
- 저장소
- fabioc-aloha/Alex_Skill_Mall
- 최근 소스 활동
- 2026년 7월 28일 21:46
- 감지된 SKILL.md 언어
- 영어
- 스타
- 4
- 포크
- 1
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
SOC 직업 분류 기준
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/fabioc-aloha/Alex_Skill_Mall --skill msal-singleton-pattern명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
Create or improve a Markdown instruction, skill, prompt, or agent from an explicitly selected file or user-identified text. Use when a user asks to optimize an existing brain artifact or create one for consistent future execution.
Clear documentation through visual excellence
Assess active Markdown brain files in a local AI agent project or plugin source without changing it. Use before modifying a brain or reviewing declared instructions, skills, prompts, agents, bundled Markdown resources, and research documentation.
| name | msal-singleton-pattern |
| description | Time Saved: 1+ hour debugging silent auth failures |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Category: Azure Time Saved: 1+ hour debugging silent auth failures Battle-tested: Yes — HeadstartWebsite, Next.js + Azure projects
Your React/Next.js app uses MSAL.js for Azure AD authentication. Login works, but token refresh fails silently. Sometimes users get logged out randomly. The console shows cryptic "interaction_in_progress" errors.
MSAL.js PublicClientApplication maintains an internal token cache and tracks in-flight auth requests. Creating multiple instances causes:
acquireTokenSilentInitialize MSAL once, share the singleton across your entire app
// ❌ BROKEN — new instance on every import/render
function getAuth() {
return new PublicClientApplication(msalConfig);
}
// ✅ CORRECT — module-level singleton with async init
let msalInstance: PublicClientApplication | null = null;
let initPromise: Promise<PublicClientApplication> | null = null;
export async function getMsalInstance(): Promise<PublicClientApplication> {
if (msalInstance) return msalInstance;
if (!initPromise) {
initPromise = (async () => {
const instance = new PublicClientApplication(msalConfig);
await instance.initialize(); // Required in MSAL.js 2.x+
msalInstance = instance;
return instance;
})();
}
return initPromise;
}
// MsalProvider.tsx
import { MsalProvider } from '@azure/msal-react';
import { getMsalInstance } from './msal-singleton';
export function AuthProvider({ children }: { children: React.ReactNode }) {
const [instance, setInstance] = useState<PublicClientApplication | null>(null);
useEffect(() => {
getMsalInstance().then(setInstance);
}, []);
if (!instance) return <Loading />;
return <MsalProvider instance={instance}>{children}</MsalProvider>;
}
// app/providers.tsx
'use client';
import { MsalProvider } from '@azure/msal-react';
import { getMsalInstance } from '@/lib/msal-singleton';
export function Providers({ children }: { children: React.ReactNode }) {
const [instance, setInstance] = useState<IPublicClientApplication | null>(null);
useEffect(() => {
getMsalInstance().then(setInstance);
}, []);
if (!instance) return null;
return <MsalProvider instance={instance}>{children}</MsalProvider>;
}
| Mistake | Symptom | Fix |
|---|---|---|
| New instance per request | Token cache miss, re-auth required | Use singleton |
Missing initialize() | Silent failures in MSAL 2.x+ | Call and await initialize() |
| Instance in component state | Re-created on re-render | Module-level singleton |
Multiple MsalProviders | "interaction_in_progress" | Single provider at app root |
// Add to singleton for debugging
export function getMsalDebugInfo() {
return {
instanceExists: !!msalInstance,
accounts: msalInstance?.getAllAccounts() ?? [],
cacheSize: Object.keys(msalInstance?.getTokenCache()?.serialize() ?? {}).length,
};
}
If accounts is empty after login, the singleton isn't being used consistently.
Source: Promoted from AI-Memory global-knowledge.md (2026-04-27)