Fix session cookie propagation; desktop creates session via POST before opening portal
This commit is contained in:
parent
69955ae80c
commit
6754af769b
3 changed files with 62 additions and 12 deletions
|
|
@ -430,14 +430,36 @@ function App() {
|
|||
}
|
||||
}
|
||||
|
||||
const openSystem = useCallback(() => {
|
||||
const openSystem = useCallback(async () => {
|
||||
if (!token) return
|
||||
setIsLaunchingSystem(true)
|
||||
try {
|
||||
// Tenta criar a sessão via API (evita dependência de redirecionamento + cookies em 3xx)
|
||||
const res = await fetch(`${apiBaseUrl}/api/machines/sessions`, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ machineToken: token, rememberMe: true }),
|
||||
})
|
||||
if (!res.ok) {
|
||||
// Fallback para o handshake por redirecionamento
|
||||
const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator"
|
||||
const redirectTarget = persona === "manager" ? "/dashboard" : "/portal"
|
||||
const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}`
|
||||
window.location.href = url
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator"
|
||||
const redirectTarget = persona === "manager" ? "/dashboard" : "/portal"
|
||||
const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}`
|
||||
window.location.href = url
|
||||
return
|
||||
}
|
||||
const persona = (config?.accessRole ?? accessRole) === "manager" ? "manager" : "collaborator"
|
||||
const redirectTarget = persona === "manager" ? "/dashboard" : "/portal"
|
||||
const url = `${resolvedAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}`
|
||||
window.location.href = url
|
||||
}, [token, config?.accessRole, accessRole, resolvedAppUrl])
|
||||
window.location.href = `${resolvedAppUrl}${redirectTarget}`
|
||||
}, [token, config?.accessRole, accessRole, resolvedAppUrl, apiBaseUrl])
|
||||
|
||||
async function reprovision() {
|
||||
if (!store) return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue