From 18cc5f69129615850e48a995f7c3406b74d8d2f4 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sat, 5 Aug 2023 21:11:48 +0100 Subject: Redesign website --- app/routes/spotify/router.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/routes/spotify/router.ts (limited to 'app/routes/spotify/router.ts') diff --git a/app/routes/spotify/router.ts b/app/routes/spotify/router.ts new file mode 100644 index 0000000..faf8f6d --- /dev/null +++ b/app/routes/spotify/router.ts @@ -0,0 +1,26 @@ +import express from 'express'; + +export const router = express.Router({ mergeParams: true }); + +router.get('/spotify/auth', (req, res, next) => { + let scope = 'user-read-currently-playing'; + let params = new URLSearchParams(); + params.append('response_type', 'code'); + params.append('client_id', process.env.SPOTIFY_CLIENT_ID); + params.append('scope', scope); + params.append('redirect_uri', process.env.SPOTIFY_REDIRECT_URI); + + res.redirect('https://accounts.spotify.com/authorize?' + params.toString()); +}); + +router.get('/spotify/auth/callback', (req, res, next) => { + if (req.query.error) { + res.send('Error: ' + req.query.error); + return; + } + if (!req.query.code) { + res.send('No code'); + return; + } + res.send('Your authentication code: ' + req.query.code); +}); -- cgit v1.2.3-70-g09d2