feat: 初始提交

This commit is contained in:
siujamo
2025-12-25 16:12:01 +08:00
commit faff32475f
77 changed files with 6123 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import type { IPublicClientApplication } from "@azure/msal-browser"
import * as AuthApi from "@/api/auth"
import type { AppDispatch } from "@/store"
import { loginSuccess } from "@/store/auth-slice"
/**
* Login with Microsoft Entra ID.
*
* @param instance Microsoft Entra ID application instance
* @param dispatch app dispatcher
* @param onSuccess callback when login succeeded
*/
export async function doMsalLogin(
instance: IPublicClientApplication,
dispatch: AppDispatch,
onSuccess?: () => void
) {
try {
const response = await instance.loginPopup({
scopes: ["openid", "profile", "email"],
})
const { accessToken, user } = await AuthApi.msalLogin(response.idToken)
dispatch(loginSuccess({ user, token: accessToken }))
if (onSuccess) onSuccess()
} catch (err) {
console.error("MSAL login failed", err)
}
}