@@ -3,14 +3,13 @@ import { useApi, useToaster } from '@/hooks';
3
3
import { Container } from '@/components/Container' ;
4
4
import { useRouter } from 'next/router' ;
5
5
import type { SSRProps } from '@/utils/ssrUtils' ;
6
- import { Button } from '@/components/Button' ;
7
- import { AppleMusicIcon } from '@/components/Icons' ;
8
6
import Script from 'next/script' ;
9
7
10
8
const Login : NextPage < SSRProps > = ( ) => {
11
9
const router = useRouter ( ) ;
12
10
const toaster = useToaster ( ) ;
13
11
const api = useApi ( ) ;
12
+ // const [musicKitLoaded, setMusicKitLoaded] = useState(false);
14
13
let inProgress = false ;
15
14
16
15
const redirectToLogin = ( ) => {
@@ -19,8 +18,12 @@ const Login: NextPage<SSRProps> = () => {
19
18
} ;
20
19
21
20
const appleMusicKitHandle = async ( ) => {
22
- // eslint-disable-next-line @typescript-eslint/naming-convention
23
- const { state } = router . query ;
21
+ // for some reason, the query from router is always empty
22
+ // const { state } = router.query;
23
+
24
+ const query = new URLSearchParams ( window . location . search ) ;
25
+ const state = query . get ( 'state' ) ;
26
+
24
27
if ( ! state ) {
25
28
redirectToLogin ( ) ;
26
29
return ;
@@ -35,9 +38,9 @@ const Login: NextPage<SSRProps> = () => {
35
38
36
39
router . push (
37
40
api . http . resolveUrl (
38
- '/auth/APPLEMUSIC/redirect ' ,
41
+ '/auth/APPLEMUSIC/callback/music ' ,
39
42
true ,
40
- `? mut=${ MUT } &state=${ state } `
43
+ `mut=${ encodeURIComponent ( MUT ) } &state=${ state } `
41
44
)
42
45
) ;
43
46
} catch ( e ) {
@@ -57,14 +60,18 @@ const Login: NextPage<SSRProps> = () => {
57
60
await MusicKit . configure ( {
58
61
developerToken,
59
62
app : {
60
- name : process . env . NEXT_PUBLIC_APPLE_APP_NAME ?? 'testing ' ,
63
+ name : process . env . NEXT_PUBLIC_APPLE_APP_NAME ?? 'stats.fm ' ,
61
64
build : process . env . NEXT_PUBLIC_APPLE_APP_BUILD ?? '1978.4.1' ,
62
65
} ,
63
66
} ) ;
64
67
await appleMusicKitHandle ( ) ;
65
68
} ) ( ) ;
66
69
} ;
67
70
71
+ // useEffect(() => {
72
+ // initializeMusicKit();
73
+ // }, [router.isReady, musicKitLoaded, router.query]);
74
+
68
75
return (
69
76
< >
70
77
< Script
@@ -75,16 +82,17 @@ const Login: NextPage<SSRProps> = () => {
75
82
< Container className = "flex min-h-[90vh] pt-24" >
76
83
< div className = "mx-auto mt-48 flex w-96 flex-col px-4" >
77
84
< h1 className = "w-full text-center text-4xl text-white" >
78
- Login to Apple Music
85
+ Authorize Apple Music
79
86
</ h1 >
80
87
< div className = "mt-8 flex flex-col gap-4" >
81
- < Button
88
+ An Apple Music popup should appear soon...
89
+ { /* <Button
82
90
onClick={appleMusicKitHandle}
83
91
className="w-full bg-applemusic/80 text-white hover:bg-applemusic/60 active:bg-applemusic/50"
84
92
>
85
93
<AppleMusicIcon className="mr-2 !fill-white" hover={false} />
86
- Continue with Apple Music
87
- </ Button >
94
+ Authorize
95
+ </Button> */ }
88
96
</ div >
89
97
</ div >
90
98
</ Container >
0 commit comments