mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Merge pull request #112 from replayio/bugfix/PRO-1250-auth-errors
This commit is contained in:
commit
721ed2c5aa
@ -1,6 +1,6 @@
|
|||||||
import { atom } from 'nanostores';
|
import { atom } from 'nanostores';
|
||||||
import { getSupabase } from '~/lib/supabase/client';
|
import { getSupabase } from '~/lib/supabase/client';
|
||||||
import type { User, Session } from '@supabase/supabase-js';
|
import { type User, type Session, AuthError } from '@supabase/supabase-js';
|
||||||
import { logStore } from './logs';
|
import { logStore } from './logs';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { isAuthenticated } from '~/lib/supabase/client';
|
import { isAuthenticated } from '~/lib/supabase/client';
|
||||||
@ -32,18 +32,24 @@ export async function initializeAuth() {
|
|||||||
|
|
||||||
isLoadingStore.set(true);
|
isLoadingStore.set(true);
|
||||||
|
|
||||||
// In local testing we've seen problems where Supabase auth hangs.
|
// We've seen Supabase Auth hang when there are multiple tabs open.
|
||||||
const timeout = setTimeout(() => {
|
// Handle this by using a timeout to ensure we don't wait indefinitely.
|
||||||
console.error('Timed out initializing auth');
|
const timeoutPromise = new Promise<{ data: { session: Session | null }; error?: AuthError }>((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve({
|
||||||
|
data: { session: null },
|
||||||
|
error: new AuthError('Timed out initializing auth'),
|
||||||
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
});
|
||||||
|
|
||||||
|
const authRes = await Promise.race([getSupabase().auth.getSession(), timeoutPromise]);
|
||||||
|
|
||||||
// Get initial session
|
// Get initial session
|
||||||
const {
|
const {
|
||||||
data: { session },
|
data: { session },
|
||||||
error,
|
error,
|
||||||
} = await getSupabase().auth.getSession();
|
} = authRes;
|
||||||
|
|
||||||
clearTimeout(timeout);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -11,7 +11,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { logStore } from './lib/stores/logs';
|
import { logStore } from './lib/stores/logs';
|
||||||
import { initializeAuth, userStore, isLoadingStore } from './lib/stores/auth';
|
import { initializeAuth, userStore, isLoadingStore } from './lib/stores/auth';
|
||||||
import { initializeUserStores } from './lib/stores/user';
|
import { initializeUserStores } from './lib/stores/user';
|
||||||
import { ToastContainer } from 'react-toastify';
|
import { ToastContainer, toast } from 'react-toastify';
|
||||||
import { Analytics } from '@vercel/analytics/remix';
|
import { Analytics } from '@vercel/analytics/remix';
|
||||||
import { AuthModal } from './components/auth/AuthModal';
|
import { AuthModal } from './components/auth/AuthModal';
|
||||||
|
|
||||||
@ -115,6 +115,12 @@ function AuthProvider({ data }: { data: LoaderData }) {
|
|||||||
// Initialize auth and user stores
|
// Initialize auth and user stores
|
||||||
initializeAuth().catch((err: Error) => {
|
initializeAuth().catch((err: Error) => {
|
||||||
logStore.logError('Failed to initialize auth', err);
|
logStore.logError('Failed to initialize auth', err);
|
||||||
|
sentryHandleError(err);
|
||||||
|
toast.error('Could not log in to the server. Please reload the page, or close other open tabs and try again', {
|
||||||
|
autoClose: false,
|
||||||
|
position: 'top-center',
|
||||||
|
theme: 'colored',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
initializeUserStores().catch((err: Error) => {
|
initializeUserStores().catch((err: Error) => {
|
||||||
logStore.logError('Failed to initialize user stores', err);
|
logStore.logError('Failed to initialize user stores', err);
|
||||||
|
Loading…
Reference in New Issue
Block a user