File size: 1,784 Bytes
dc1f75e
 
 
 
349f22c
dc1f75e
2f67ecf
 
dc1f75e
 
 
 
 
 
 
 
 
 
 
 
 
 
973dd4c
dc1f75e
 
 
 
76fb273
973dd4c
dc1f75e
 
 
 
 
 
c976c65
 
 
 
2f67ecf
dc1f75e
 
 
 
 
c976c65
150c960
c976c65
 
2f67ecf
dc1f75e
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use client';

import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { CircleNotch as LoaderCircle } from '@phosphor-icons/react';
import { getSupabase } from '@/lib/supabase';
import { motion } from 'framer-motion';
import { fadeUp } from '@/lib/animations';

export default function AuthCallback() {
  const router = useRouter();
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    const code = params.get('code');

    if (!code) {
      router.replace('/auth');
      return;
    }

    getSupabase().auth.exchangeCodeForSession(code).then(({ error }: { error?: { message: string } | null }) => {
      if (error) {
        setError(error.message);
        return;
      }
      router.replace('/analyze');
    }).catch((e: Error) => {
      setError(e.message || 'Unknown error');
    });
  }, [router]);

  if (error) {
    return (
      <div className="min-h-screen flex items-center justify-center bg-void">
        <motion.div variants={fadeUp} initial={{ y: 24 }} animate="show" className="bg-surface-0 rounded-2xl border border-error/20 p-8 max-w-sm text-center">
          <h2 className="text-lg font-semibold text-error mb-2">Sign in failed</h2>
          <p className="text-sm text-error">{error}</p>
        </motion.div>
      </div>
    );
  }

  return (
    <div className="min-h-screen flex items-center justify-center bg-void">
      <motion.div variants={fadeUp} initial={{ y: 24 }} animate="show" className="text-center">
        <LoaderCircle className="w-8 h-8 text-accent-cyan animate-spin mx-auto mb-4" />
        <p className="text-sm text-text-muted">Completing sign in...</p>
      </motion.div>
    </div>
  );
}