@@ -25,6 +25,7 @@ import { FeatureDetails } from "./featured-checkins";
2525import {
2626 refreshStoredStrabospotAuth ,
2727 clearStoredStrabospotAuth ,
28+ loginAndRefreshStrabospotFromUUID ,
2829} from "./strabospot-integration" ;
2930import { getStoredRockdPersonId , clearRockdAuth } from "../../login/rockd-auth" ;
3031
@@ -190,10 +191,40 @@ export function Page() {
190191 useEffect ( ( ) => {
191192 let cancelled = false ;
192193 async function checkStrabospotSync ( ) {
193- const ok = await refreshStoredStrabospotAuth ( ) ;
194- if ( cancelled ) return ;
195- setIsStrabospotSynced ( ok ) ;
196- setIsCheckingStrabospotSync ( false ) ;
194+ try {
195+ const uuid = new URLSearchParams ( window . location . search ) . get ( "u" ) ;
196+ if ( uuid != null ) {
197+ const auth = await loginAndRefreshStrabospotFromUUID ( uuid ) ;
198+ if ( cancelled ) return ;
199+
200+ const isFullyLinked =
201+ auth . accessToken != null &&
202+ auth . refreshToken != null &&
203+ auth . datasetId != null &&
204+ auth . projectId != null ;
205+
206+ setIsStrabospotSynced ( isFullyLinked ) ;
207+
208+ const cleanURL = `${ window . location . origin } ${ window . location . pathname } ` ;
209+ window . history . replaceState ( { } , "" , cleanURL ) ;
210+
211+ return ;
212+ }
213+ const ok = await refreshStoredStrabospotAuth ( ) ;
214+ if ( cancelled ) return ;
215+ setIsStrabospotSynced ( ok ) ;
216+ } catch ( err : any ) {
217+ console . error ( "Failed to complete StraboSpot login:" , err ) ;
218+ console . error ( "Message:" , err ?. message ) ;
219+
220+ if ( cancelled ) return ;
221+
222+ setIsStrabospotSynced ( false ) ;
223+ } finally {
224+ if ( ! cancelled ) {
225+ setIsCheckingStrabospotSync ( false ) ;
226+ }
227+ }
197228 }
198229 checkStrabospotSync ( ) ;
199230 return ( ) => {
@@ -207,8 +238,10 @@ export function Page() {
207238 setIsStrabospotSynced ( false ) ;
208239 return ;
209240 }
210-
211- window . location . href = "/dev/strabospot/login" ;
241+ const callbackURL = `${ window . location . origin } /dev/strabospot` ;
242+ const strabospotLoginURL = new URL ( "https://strabospot.org/rockd_login" ) ;
243+ strabospotLoginURL . searchParams . set ( "redirect_uri" , callbackURL ) ;
244+ window . location . href = strabospotLoginURL . toString ( ) ;
212245 }
213246
214247 const style = useMapStyle (
0 commit comments