11import type {
2- GetStaticPaths ,
3- GetStaticProps ,
4- InferGetStaticPropsType ,
2+ GetServerSideProps ,
3+ InferGetServerSidePropsType
54} from 'next' ;
65import { useState , useEffect , useCallback } from 'react' ;
76import { api } from '~/utils/api' ;
@@ -41,8 +40,8 @@ const FileCard = styled('div')({
4140} ) ;
4241
4342const BrowsePage = ( {
44- userId ,
45- } : InferGetStaticPropsType < typeof getStaticProps > ) => {
43+ login ,
44+ } : InferGetServerSidePropsType < typeof getServerSideProps > ) => {
4645 const [ token , setToken ] = useState < string | null > ( null ) ;
4746 const utils = api . useContext ( ) ;
4847
@@ -76,23 +75,19 @@ const BrowsePage = ({
7675 // Check for stored token on mount
7776 useEffect ( ( ) => {
7877 const storedToken = localStorage . getItem ( 'authToken' ) ;
79- if ( storedToken ) {
80- if ( ! currentUser || currentUser . name === userId ) {
81- setToken ( storedToken ) ;
82- } else {
83- localStorage . removeItem ( 'authToken' ) ;
84- }
85- } else if ( ! signInMutation . isPending && ! signInMutation . error ) {
78+ if ( storedToken && ! login ) {
79+ setToken ( storedToken ) ;
80+ } else if ( ! signInMutation . isSuccess && ! signInMutation . isPending && ! signInMutation . error ) {
8681 void handleLogin ( ) ;
8782 }
88- } , [ currentUser , userId , handleLogin , signInMutation ] ) ;
83+ } , [ currentUser , login , handleLogin , signInMutation ] ) ;
8984
9085 if ( signInMutation . error ) {
9186 return (
9287 < Container >
93- < Title > Login Failed </ Title >
88+ < Title > Access Denied </ Title >
9489 < div className = "text-center text-red-500" >
95- Please refresh to try again.
90+ Login failed. Please refresh to try again.
9691 </ div >
9792 </ Container >
9893 ) ;
@@ -102,16 +97,8 @@ const BrowsePage = ({
10297 return (
10398 < Container >
10499 < Title > Waiting for authentication...</ Title >
105- </ Container >
106- ) ;
107- }
108-
109- if ( currentUser . name !== userId ) {
110- return (
111- < Container >
112- < Title > Access Denied</ Title >
113100 < div className = "text-center text-red-500" >
114- You cannot access files that do not belong to you .
101+ Please refresh this page if nothing happens .
115102 </ div >
116103 </ Container >
117104 ) ;
@@ -146,21 +133,14 @@ const BrowsePage = ({
146133 ) ;
147134} ;
148135
149- export const getStaticProps = ( async ( { params } ) => {
150- const userId = params ! . userId as string ;
136+ export const getServerSideProps = ( async ( { query } ) => {
137+ const login = query ?. login ?? null ;
151138
152139 return {
153140 props : {
154- userId ,
141+ login ,
155142 } ,
156143 } ;
157- } ) satisfies GetStaticProps ;
158-
159- export const getStaticPaths = ( async ( ) => {
160- return {
161- paths : [ ] ,
162- fallback : 'blocking' ,
163- } ;
164- } ) satisfies GetStaticPaths ;
144+ } ) satisfies GetServerSideProps ;
165145
166146export default BrowsePage ;
0 commit comments