Skip to content

Commit 2d3374d

Browse files
committed
fix(auth): fix all apple auth issues
1 parent 0212767 commit 2d3374d

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

next.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ module.exports = withBundleAnalyzer({
3434
protocol: 'https',
3535
hostname: 'crowdin-static.downloads.crowdin.com',
3636
},
37+
{
38+
protocol: 'https',
39+
hostname: '**.mzstatic.com',
40+
},
3741
],
3842
},
3943
async redirects() {

src/pages/api/auth/apple-music.tsx src/pages/auth/apple-music.tsx

+19-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { useApi, useToaster } from '@/hooks';
33
import { Container } from '@/components/Container';
44
import { useRouter } from 'next/router';
55
import type { SSRProps } from '@/utils/ssrUtils';
6-
import { Button } from '@/components/Button';
7-
import { AppleMusicIcon } from '@/components/Icons';
86
import Script from 'next/script';
97

108
const Login: NextPage<SSRProps> = () => {
119
const router = useRouter();
1210
const toaster = useToaster();
1311
const api = useApi();
12+
// const [musicKitLoaded, setMusicKitLoaded] = useState(false);
1413
let inProgress = false;
1514

1615
const redirectToLogin = () => {
@@ -19,8 +18,12 @@ const Login: NextPage<SSRProps> = () => {
1918
};
2019

2120
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+
2427
if (!state) {
2528
redirectToLogin();
2629
return;
@@ -35,9 +38,9 @@ const Login: NextPage<SSRProps> = () => {
3538

3639
router.push(
3740
api.http.resolveUrl(
38-
'/auth/APPLEMUSIC/redirect',
41+
'/auth/APPLEMUSIC/callback/music',
3942
true,
40-
`?mut=${MUT}&state=${state}`
43+
`mut=${encodeURIComponent(MUT)}&state=${state}`
4144
)
4245
);
4346
} catch (e) {
@@ -57,14 +60,18 @@ const Login: NextPage<SSRProps> = () => {
5760
await MusicKit.configure({
5861
developerToken,
5962
app: {
60-
name: process.env.NEXT_PUBLIC_APPLE_APP_NAME ?? 'testing',
63+
name: process.env.NEXT_PUBLIC_APPLE_APP_NAME ?? 'stats.fm',
6164
build: process.env.NEXT_PUBLIC_APPLE_APP_BUILD ?? '1978.4.1',
6265
},
6366
});
6467
await appleMusicKitHandle();
6568
})();
6669
};
6770

71+
// useEffect(() => {
72+
// initializeMusicKit();
73+
// }, [router.isReady, musicKitLoaded, router.query]);
74+
6875
return (
6976
<>
7077
<Script
@@ -75,16 +82,17 @@ const Login: NextPage<SSRProps> = () => {
7582
<Container className="flex min-h-[90vh] pt-24">
7683
<div className="mx-auto mt-48 flex w-96 flex-col px-4">
7784
<h1 className="w-full text-center text-4xl text-white">
78-
Login to Apple Music
85+
Authorize Apple Music
7986
</h1>
8087
<div className="mt-8 flex flex-col gap-4">
81-
<Button
88+
An Apple Music popup should appear soon...
89+
{/* <Button
8290
onClick={appleMusicKitHandle}
8391
className="w-full bg-applemusic/80 text-white hover:bg-applemusic/60 active:bg-applemusic/50"
8492
>
8593
<AppleMusicIcon className="mr-2 !fill-white" hover={false} />
86-
Continue with Apple Music
87-
</Button>
94+
Authorize
95+
</Button> */}
8896
</div>
8997
</div>
9098
</Container>

0 commit comments

Comments
 (0)