@@ -14,33 +14,43 @@ export default function Login({}) {
1414 const [ url , setUrl ] = useState ( "" ) ;
1515
1616 async function postData ( ) {
17- await fetch ( `/api/v1/auth/login` , {
18- method : "POST" ,
19- headers : { "Content-Type" : "application/json" } ,
20- body : JSON . stringify ( { email, password } ) ,
21- } )
22- . then ( ( res ) => res . json ( ) )
23- . then ( async ( res ) => {
24- if ( res . user ) {
25- setCookie ( "session" , res . token ) ;
26- if ( res . user . external_user ) {
27- router . push ( "/portal" ) ;
28- } else {
29- if ( res . user . firstLogin ) {
30- router . push ( "/onboarding" ) ;
17+ try {
18+ await fetch ( `/api/v1/auth/login` , {
19+ method : "POST" ,
20+ headers : { "Content-Type" : "application/json" } ,
21+ body : JSON . stringify ( { email, password } ) ,
22+ } )
23+ . then ( ( res ) => res . json ( ) )
24+ . then ( async ( res ) => {
25+ if ( res . user ) {
26+ setCookie ( "session" , res . token ) ;
27+ if ( res . user . external_user ) {
28+ router . push ( "/portal" ) ;
3129 } else {
32- router . push ( "/" ) ;
30+ if ( res . user . firstLogin ) {
31+ router . push ( "/onboarding" ) ;
32+ } else {
33+ router . push ( "/" ) ;
34+ }
3335 }
36+ } else {
37+ toast ( {
38+ variant : "destructive" ,
39+ title : "Error" ,
40+ description :
41+ "There was an error logging in, please try again. If this issue persists, please contact support via the discord." ,
42+ } ) ;
3443 }
35- } else {
36- toast ( {
37- variant : "destructive" ,
38- title : "Error" ,
39- description :
40- "There was an error logging in, please try again. If this issue persists, please contact support via the discord. ",
41- } ) ;
42- }
44+ } ) ;
45+ } catch ( error ) {
46+ console . error ( error ) ;
47+ toast ( {
48+ variant : "destructive" ,
49+ title : "Database Error ",
50+ description :
51+ "This is an issue with the database, please check the docker logs or contact support via discord." ,
4352 } ) ;
53+ }
4454 }
4555
4656 async function oidcLogin ( ) {
0 commit comments