@@ -5,11 +5,14 @@ import {
55 getOuterbaseWorkspace ,
66 loginOuterbaseByPassword ,
77} from "@/outerbase-cloud/api" ;
8- import { OuterbaseAPIError } from "@/outerbase-cloud/api-type" ;
8+ import {
9+ OuterbaseAPIError ,
10+ OuterbaseAPISession ,
11+ } from "@/outerbase-cloud/api-type" ;
912import { LucideLoader } from "lucide-react" ;
1013import Link from "next/link" ;
1114import { useRouter } from "next/navigation" ;
12- import { useCallback , useState } from "react" ;
15+ import { useCallback , useEffect , useState } from "react" ;
1316import ThemeLayout from "../(theme)/theme_layout" ;
1417import { LoginBaseSpaceship } from "./starbase-portal" ;
1518
@@ -19,6 +22,7 @@ export default function SigninPage() {
1922 const [ error , setError ] = useState ( "" ) ;
2023 const router = useRouter ( ) ;
2124 const [ loading , setLoading ] = useState ( false ) ;
25+ const [ session , setSession ] = useState < OuterbaseAPISession > ( ) ;
2226
2327 const onLoginClicked = useCallback ( ( ) => {
2428 setLoading ( true ) ;
@@ -28,22 +32,35 @@ export default function SigninPage() {
2832 localStorage . setItem ( "session" , JSON . stringify ( session ) ) ;
2933 localStorage . setItem ( "ob-token" , session . token ) ;
3034
31- getOuterbaseWorkspace ( )
32- . then ( ( w ) => {
33- router . push ( `/w/${ w . items [ 0 ] . short_name } ` ) ;
34- } )
35- . catch ( console . error )
36- . finally ( ( ) => {
37- setLoading ( false ) ;
38- } ) ;
35+ setSession ( session ) ;
3936 } )
4037 . catch ( ( e ) => {
4138 setLoading ( false ) ;
4239 if ( e instanceof OuterbaseAPIError ) {
4340 setError ( e . description ) ;
4441 }
4542 } ) ;
46- } , [ email , password , router ] ) ;
43+ } , [ email , password ] ) ;
44+
45+ useEffect ( ( ) => {
46+ if ( ! session ) return ;
47+
48+ const redirect = localStorage . getItem ( "continue-redirect" ) ;
49+ if ( redirect ) {
50+ localStorage . removeItem ( "continue-redirect" ) ;
51+ router . push ( redirect ) ;
52+ return ;
53+ }
54+
55+ getOuterbaseWorkspace ( )
56+ . then ( ( w ) => {
57+ router . push ( `/w/${ w . items [ 0 ] . short_name } ` ) ;
58+ } )
59+ . catch ( console . error )
60+ . finally ( ( ) => {
61+ setLoading ( false ) ;
62+ } ) ;
63+ } , [ session , router ] ) ;
4764
4865 return (
4966 < ThemeLayout overrideTheme = "dark" >
0 commit comments