@@ -52,24 +52,33 @@ export const getServerSideProps: GetServerSideProps = withEnv(
5252 ensureLogin (
5353 withAuthSSR ( async ( context , ssrApi ) => {
5454 const { baseId } = context . query ;
55- const userLastVisit = await ssrApi . getUserLastVisit (
56- LastVisitResourceType . Table ,
57- baseId as string
58- ) ;
55+ const [ userLastVisit , tables ] = await Promise . all ( [
56+ ssrApi . getUserLastVisit ( LastVisitResourceType . Table , baseId as string ) ,
57+ ssrApi . getTables ( baseId as string ) ,
58+ ] ) ;
59+
60+ if ( tables . length && userLastVisit && userLastVisit . childResourceId ) {
61+ // if userLastVisit.resourceId has no permission to the tables, redirect to the first table
62+ if ( tables . find ( ( table ) => table . id === userLastVisit . resourceId ) ) {
63+ return {
64+ redirect : {
65+ destination : `/base/${ baseId } /${ userLastVisit . resourceId } /${ userLastVisit . childResourceId } ` ,
66+ permanent : false ,
67+ } ,
68+ } ;
69+ }
5970
60- if ( userLastVisit && userLastVisit . childResourceId ) {
6171 return {
6272 redirect : {
63- destination : `/base/${ baseId } /${ userLastVisit . resourceId } /${ userLastVisit . childResourceId } ` ,
73+ destination : `/base/${ baseId } /${ tables [ 0 ] . id } /${ tables [ 0 ] . defaultViewId } ` ,
6474 permanent : false ,
6575 } ,
6676 } ;
6777 }
6878
6979 const queryClient = new QueryClient ( ) ;
7080
71- const [ tables ] = await Promise . all ( [
72- ssrApi . getTables ( baseId as string ) ,
81+ await Promise . all ( [
7382 queryClient . fetchQuery ( {
7483 queryKey : ReactQueryKeys . base ( baseId as string ) ,
7584 queryFn : ( { queryKey } ) =>
0 commit comments