feat: external session API + magic login (merge from open-refboard 02750ba)
Publish container image / build-and-push (push) Canceled after 0s
Publish container image / build-and-push (push) Canceled after 0s
- POST /api/external/session: bridge auth via X-API-Key, JIT user provisioning - GET /api/external/health: capability report - /magic frontend route: consumes ?token= JWT, redirects - docs/EXTERNAL-API.md: bridge contract spec
This commit is contained in:
1 parent
4cda9c8c0a
commit
0504df49b0
7 files changed
+428
-43
No files matched your search
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* MagicLogin — consumes `?token=<JWT>` on ANY route.
|
||||
*
|
||||
* Bridges (AYON addon, Nextcloud app, ...) send users to:
|
||||
* https://<refboard>/<any-path>?token=<jwt>
|
||||
*
|
||||
* This component validates the token against /api/auth/me, stores it,
|
||||
* and redirects to the destination path (also given via `redirect` query
|
||||
* param, default `/`).
|
||||
*/
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useNavigate, useSearchParams, useLocation } from 'react-router-dom';
|
||||
import { useAuth } from '../auth';
|
||||
import { getMe } from '../api';
|
||||
|
||||
export default function MagicLogin() {
|
||||
const [params] = useSearchParams();
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const { login } = useAuth();
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const token = params.get('token');
|
||||
if (!token) {
|
||||
setError('No token provided');
|
||||
return;
|
||||
}
|
||||
|
||||
// Temporarily store so getMe() picks it up (it reads localStorage)
|
||||
localStorage.setItem('refboard_token', token);
|
||||
getMe()
|
||||
.then((res) => {
|
||||
const user = res.data.user || res.data;
|
||||
login(token, user);
|
||||
const redirect = params.get('redirect') || '/';
|
||||
navigate(redirect, { replace: true });
|
||||
})
|
||||
.catch(() => {
|
||||
localStorage.removeItem('refboard_token');
|
||||
setError('Invalid or expired token');
|
||||
});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
// If we're mounted on a /board/:id path, keep that path as redirect target
|
||||
const redirectPath = location.pathname !== '/magic' ? location.pathname : params.get('redirect') || '/';
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
|
||||
height: '100vh', background: '#1a1a1a', color: '#e0e0e0', fontSize: '16px', gap: '12px',
|
||||
}}>
|
||||
<div>Magic-Login fehlgeschlagen: {error}</div>
|
||||
<button
|
||||
onClick={() => navigate('/login', { replace: true })}
|
||||
style={{
|
||||
padding: '8px 16px', background: '#2d2d2d', color: '#e0e0e0',
|
||||
border: '1px solid #444', borderRadius: '6px', cursor: 'pointer',
|
||||
}}
|
||||
>
|
||||
Zum Login
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
height: '100vh', background: '#1a1a1a', color: '#e0e0e0', fontSize: '18px',
|
||||
}}>
|
||||
Anmelden...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user