fix: CallbackPage handles verification_pending and merge_pending states
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 38s
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 38s
This commit is contained in:
@@ -10,15 +10,20 @@ interface SessionResponse {
|
|||||||
data: { user: User };
|
data: { user: User };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PendingState =
|
||||||
|
| { kind: 'verification_pending'; email: string }
|
||||||
|
| { kind: 'merge_pending'; email: string; provider: string };
|
||||||
|
|
||||||
export default function CallbackPage() {
|
export default function CallbackPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { setUser } = useAuthContext();
|
const { setUser } = useAuthContext();
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [pending, setPending] = useState<PendingState | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
// --- Erreur OAuth explicite (state=error, error=access_denied, etc.) ---
|
// --- Erreur OAuth explicite ---
|
||||||
const oauthError = params.get('error');
|
const oauthError = params.get('error');
|
||||||
if (oauthError) {
|
if (oauthError) {
|
||||||
const desc = params.get('error_description') ?? oauthError;
|
const desc = params.get('error_description') ?? oauthError;
|
||||||
@@ -26,6 +31,21 @@ export default function CallbackPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Pending states (verification / merge) ---
|
||||||
|
const status = params.get('status');
|
||||||
|
if (status === 'verification_pending') {
|
||||||
|
setPending({ kind: 'verification_pending', email: params.get('email') ?? '' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (status === 'merge_pending') {
|
||||||
|
setPending({
|
||||||
|
kind: 'merge_pending',
|
||||||
|
email: params.get('email') ?? '',
|
||||||
|
provider: params.get('provider') ?? '',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Flow PKCE : ?code= présent ---
|
// --- Flow PKCE : ?code= présent ---
|
||||||
const code = params.get('code');
|
const code = params.get('code');
|
||||||
if (code) {
|
if (code) {
|
||||||
@@ -38,7 +58,6 @@ export default function CallbackPage() {
|
|||||||
|
|
||||||
exchangeCode(code, verifier, redirectUri)
|
exchangeCode(code, verifier, redirectUri)
|
||||||
.then((tokens) => {
|
.then((tokens) => {
|
||||||
// Pass tokens to backend to set httpOnly cookies + sync user
|
|
||||||
return apiFetch<SessionResponse>('/auth/session', {
|
return apiFetch<SessionResponse>('/auth/session', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -55,7 +74,7 @@ export default function CallbackPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Flow session (Step 2 — token JWT passé en query param) ---
|
// --- Flow session (token JWT en query param) ---
|
||||||
const token = params.get('token');
|
const token = params.get('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
apiFetch<SessionResponse>('/auth/session', {
|
apiFetch<SessionResponse>('/auth/session', {
|
||||||
@@ -74,6 +93,47 @@ export default function CallbackPage() {
|
|||||||
navigate('/', { replace: true });
|
navigate('/', { replace: true });
|
||||||
}, [navigate, setUser]);
|
}, [navigate, setUser]);
|
||||||
|
|
||||||
|
// --- Pending UI ---
|
||||||
|
if (pending) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center gap-6 pt-20 max-w-md mx-auto text-center">
|
||||||
|
{pending.kind === 'verification_pending' ? (
|
||||||
|
<>
|
||||||
|
<div className="text-4xl">📧</div>
|
||||||
|
<h2 className="text-lg font-semibold text-od-text">Vérifie ton email</h2>
|
||||||
|
<p className="text-sm text-od-muted">
|
||||||
|
Un email de vérification a été envoyé à{' '}
|
||||||
|
<span className="text-od-text font-mono">{pending.email}</span>.
|
||||||
|
<br />
|
||||||
|
Clique sur le lien pour activer ton compte.
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="text-4xl">🔗</div>
|
||||||
|
<h2 className="text-lg font-semibold text-od-text">Fusion de compte</h2>
|
||||||
|
<p className="text-sm text-od-muted">
|
||||||
|
Un compte existe déjà avec l'email{' '}
|
||||||
|
<span className="text-od-text font-mono">{pending.email}</span>.
|
||||||
|
<br />
|
||||||
|
Un email a été envoyé pour fusionner ton compte{' '}
|
||||||
|
<span className="text-od-accent capitalize">{pending.provider}</span>.
|
||||||
|
<br />
|
||||||
|
Clique sur le lien dans l'email pour confirmer.
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<a
|
||||||
|
href="/login"
|
||||||
|
className="font-mono text-xs text-od-muted hover:text-od-text transition-colors"
|
||||||
|
>
|
||||||
|
← Retour à la connexion
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Error UI ---
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center gap-4 pt-20">
|
<div className="flex flex-col items-center gap-4 pt-20">
|
||||||
|
|||||||
Reference in New Issue
Block a user