| | import apiClient from './apiClient'; |
| |
|
| | class LinkedInAuthService { |
| | |
| | |
| | |
| | |
| | async initiateAuth() { |
| | try { |
| | const response = await apiClient.post('/accounts', { |
| | account_name: 'LinkedIn Account', |
| | social_network: 'LinkedIn' |
| | }); |
| | |
| | if (response.data.success && response.data.authorization_url) { |
| | return { |
| | success: true, |
| | authorization_url: response.data.authorization_url, |
| | state: response.data.state |
| | }; |
| | } else { |
| | throw new Error(response.data.message || 'Failed to initiate LinkedIn authentication'); |
| | } |
| | } catch (error) { |
| | return { |
| | success: false, |
| | message: error.response?.data?.message || 'Failed to start LinkedIn authentication' |
| | }; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | async handleCallback(code, state) { |
| | try { |
| | const response = await apiClient.post('/accounts/callback', { |
| | code: code, |
| | state: state, |
| | social_network: 'LinkedIn' |
| | }); |
| | |
| | return response.data; |
| | } catch (error) { |
| | return { |
| | success: false, |
| | message: error.response?.data?.message || 'Failed to complete LinkedIn authentication' |
| | }; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | async getLinkedInAccounts() { |
| | try { |
| | const response = await apiClient.get('/accounts'); |
| | |
| | |
| | let accounts = []; |
| | |
| | if (response.data && response.data.success && response.data.accounts) { |
| | |
| | accounts = response.data.accounts; |
| | } else if (Array.isArray(response.data)) { |
| | |
| | accounts = response.data; |
| | } else { |
| | throw new Error('Unexpected response format from API'); |
| | } |
| | |
| | |
| | const linkedinAccounts = accounts.filter( |
| | account => account && account.social_network && account.social_network.toLowerCase() === 'linkedin' |
| | ); |
| | |
| | return { success: true, accounts: linkedinAccounts }; |
| | } catch (error) { |
| | return { success: false, accounts: [], message: error.response?.data?.message || 'Failed to fetch LinkedIn accounts' }; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async deleteLinkedInAccount(accountId) { |
| | try { |
| | const response = await apiClient.delete(`/accounts/${accountId}`); |
| | |
| | return response.data; |
| | } catch (error) { |
| | return { |
| | success: false, |
| | message: error.response?.data?.message || 'Failed to delete LinkedIn account' |
| | }; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async setPrimaryAccount(accountId) { |
| | try { |
| | const response = await apiClient.put(`/accounts/${accountId}/primary`); |
| | |
| | return response.data; |
| | } catch (error) { |
| | return { |
| | success: false, |
| | message: error.response?.data?.message || 'Failed to set primary account' |
| | }; |
| | } |
| | } |
| | } |
| |
|
| | export default new LinkedInAuthService(); |