Skip to content

Commit ea69076

Browse files
google-labs-jules[bot]arii
authored andcommitted
feat: extract auth logic to service
Refactored the authentication logic from SpotifyDisplay.tsx into a dedicated authService.ts. This improves code organization and reusability by centralizing the sign-in and sign-out functionality. - Created services/authService.ts with login and logout functions. - Updated SpotifyDisplay.tsx to use the new authService.
1 parent 361c482 commit ea69076

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

components/SpotifyDisplay.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import Menu from '@mui/material/Menu'
1717
import MenuItem from '@mui/material/MenuItem'
1818
import Slider from '@mui/material/Slider'
1919
import Typography from '@mui/material/Typography'
20-
import { signIn, signOut, useSession } from 'next-auth/react'
20+
import { useSession } from 'next-auth/react'
2121
import { useCallback, useEffect, useRef, useState } from 'react'
22+
import { login, logout } from '@/services/authService'
2223

2324
interface SpotifyDevice {
2425
id: string
@@ -171,11 +172,11 @@ const SpotifyDisplay = () => {
171172
}
172173

173174
const handleSpotifyLogin = () => {
174-
signIn('spotify', { callbackUrl: '/' })
175+
login()
175176
}
176177

177178
const handleSpotifyLogout = () => {
178-
signOut({ callbackUrl: '/' })
179+
logout()
179180
}
180181

181182
if (!spotifyLoggedIn) {

services/authService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// services/authService.ts
2+
import { signIn, signOut } from 'next-auth/react';
3+
4+
export const login = () => {
5+
signIn('spotify', { callbackUrl: '/' });
6+
};
7+
8+
export const logout = () => {
9+
signOut({ callbackUrl: '/' });
10+
};

0 commit comments

Comments
 (0)