@@ -47,17 +47,17 @@ export function AuthProvider({
4747 near . authStatus ( ) === "SignedIn" ,
4848 ) ;
4949 const [ isAuthorized , setIsAuthorized ] = useState < boolean > (
50- ( ) => sessionStorage . getItem ( "isAuthorized" ) === "true" ,
50+ ( ) => localStorage . getItem ( "isAuthorized" ) === "true" ,
5151 ) ;
5252 const [ nonce , setNonce ] = useState < string | null > ( null ) ;
5353 const [ recipient , setRecipient ] = useState < string | null > ( null ) ;
5454 const initialCheckRef = useRef ( true ) ;
5555
5656 useEffect ( ( ) => {
5757 if ( isAuthorized ) {
58- sessionStorage . setItem ( "isAuthorized" , "true" ) ;
58+ localStorage . setItem ( "isAuthorized" , "true" ) ;
5959 } else {
60- sessionStorage . removeItem ( "isAuthorized" ) ;
60+ localStorage . removeItem ( "isAuthorized" ) ;
6161 }
6262 } , [ isAuthorized ] ) ;
6363
@@ -95,29 +95,10 @@ export function AuthProvider({
9595 } , [ ] ) ;
9696
9797 useEffect ( ( ) => {
98- const handleAccountChange = async ( newAccountId : string | null ) => {
99- if ( newAccountId === currentAccountId ) {
100- return ;
101- }
102-
103- setCurrentAccountId ( newAccountId ) ;
104- setIsSignedIn ( ! ! newAccountId ) ;
105-
106- if ( newAccountId ) {
107- toast ( {
108- title : "Wallet Connected" ,
109- description : `Connected as: ${ newAccountId } ` ,
110- variant : "success" ,
111- duration : 1000 ,
112- } ) ;
113- await Promise . all ( [ checkAuthorization ( ) , initiateLogin ( newAccountId ) ] ) ;
114- } else {
115- toast ( {
116- title : "Wallet Disconnected" ,
117- description : "You have been signed out successfully." ,
118- variant : "success" ,
119- duration : 1000 ,
120- } ) ;
98+ const handleAccountChange = ( newAccountId : string | null ) => {
99+ if ( newAccountId !== currentAccountId ) {
100+ setCurrentAccountId ( newAccountId ) ;
101+ setIsSignedIn ( ! ! newAccountId ) ;
121102 }
122103 } ;
123104
@@ -132,7 +113,27 @@ export function AuthProvider({
132113 return ( ) => {
133114 near . event . offAccount ( accountListener ) ;
134115 } ;
135- } , [ checkAuthorization , initiateLogin ] ) ;
116+ } , [ currentAccountId ] ) ;
117+
118+ useEffect ( ( ) => {
119+ if ( currentAccountId ) {
120+ toast ( {
121+ title : "Wallet Connected" ,
122+ description : `Connected as: ${ currentAccountId } ` ,
123+ variant : "success" ,
124+ duration : 1000 ,
125+ } ) ;
126+ Promise . all ( [ checkAuthorization ( ) , initiateLogin ( currentAccountId ) ] ) ;
127+ } else {
128+ setIsAuthorized ( false ) ;
129+ toast ( {
130+ title : "Wallet Disconnected" ,
131+ description : "You have been signed out successfully." ,
132+ variant : "success" ,
133+ duration : 1000 ,
134+ } ) ;
135+ }
136+ } , [ currentAccountId , checkAuthorization , initiateLogin ] ) ;
136137
137138 const handleSignIn = async ( ) : Promise < void > => {
138139 try {
@@ -203,6 +204,7 @@ export function AuthProvider({
203204 error ,
204205 ) ;
205206 }
207+ setIsAuthorized ( false ) ;
206208 near . signOut ( ) ;
207209 } ;
208210
0 commit comments