diff --git a/ui/package-lock.json b/ui/package-lock.json index 9489ab29d4..96a9720209 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -828,6 +828,14 @@ "integrity": "sha512-I2EjI9TbEFJNLziNPFfpo64PNanOaK17iL2kTW/jGlGOa4bvHw4VEied83kOEB7NJjXf1KfvmsQ2aEjy3xjiGg==", "dev": true }, + "@influxdata/influx": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.1.1.tgz", + "integrity": "sha512-ANHGcrjXc5PRZfeAknkGIvQbNb8eI3I8iqTxPLKZHQvqQm3SD3brbE5CV+Qt/iRsszu3beIL2CjUBrU+wQLcWg==", + "requires": { + "axios": "^0.18.0" + } + }, "@mrmlnc/readdir-enhanced": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz", diff --git a/ui/package.json b/ui/package.json index cbbfb197b4..18754a7d6f 100644 --- a/ui/package.json +++ b/ui/package.json @@ -114,6 +114,7 @@ "typescript": "^3.1.3" }, "dependencies": { + "@influxdata/influx": "^0.1.1", "axios": "^0.18.0", "babel-polyfill": "^6.26.0", "bignumber.js": "^4.0.2", diff --git a/ui/src/Logout.tsx b/ui/src/Logout.tsx index a8536a3532..158fee6224 100644 --- a/ui/src/Logout.tsx +++ b/ui/src/Logout.tsx @@ -3,7 +3,7 @@ import {PureComponent} from 'react' import {withRouter, WithRouterProps} from 'react-router' // APIs -import {logout} from 'src/me/apis' +import {client} from 'src/utils/api' // Components import {ErrorHandling} from 'src/shared/decorators/errors' @@ -21,7 +21,7 @@ export class Logout extends PureComponent { } private handleSignOut = async () => { - await logout() + await client.auth.signout() this.props.router.push(`/signin`) } diff --git a/ui/src/me/apis/index.ts b/ui/src/me/apis/index.ts index 5458e07205..9548b7057d 100644 --- a/ui/src/me/apis/index.ts +++ b/ui/src/me/apis/index.ts @@ -1,5 +1,5 @@ -import {baseAPI} from 'src/utils/api' +import {client} from 'src/utils/api' export const logout = async (): Promise => { - await baseAPI.signoutPost() + await client.auth.signout() } diff --git a/ui/src/onboarding/actions/index.ts b/ui/src/onboarding/actions/index.ts index 14fbce6adb..33cd569cae 100644 --- a/ui/src/onboarding/actions/index.ts +++ b/ui/src/onboarding/actions/index.ts @@ -5,10 +5,11 @@ import {SetupSuccess, SetupError} from 'src/shared/copy/notifications' // Actions import {notify} from 'src/shared/actions/notifications' +import {client} from 'src/utils/api' + // Types import { SetupParams, - signin as signinAJAX, setSetupParams as setSetupParamsAJAX, } from 'src/onboarding/apis' @@ -75,10 +76,9 @@ export const setupAdmin = (setupParams: SetupParams) => async dispatch => { dispatch(setOrganizationID(orgID)) dispatch(setBucketID(bucketID)) - await signinAJAX({ - username: setupParams.username, - password: setupParams.password, - }) + const {username, password} = setupParams + + await client.auth.signin(username, password) dispatch(notify(SetupSuccess)) } catch (err) { console.error(err) diff --git a/ui/src/onboarding/apis/index.ts b/ui/src/onboarding/apis/index.ts index fdd0c34ce1..cfe25a5c34 100644 --- a/ui/src/onboarding/apis/index.ts +++ b/ui/src/onboarding/apis/index.ts @@ -1,7 +1,7 @@ // Libraries import _ from 'lodash' -import {baseAPI, setupAPI, sourcesAPI} from 'src/utils/api' +import {setupAPI, sourcesAPI} from 'src/utils/api' // Utils import { @@ -10,6 +10,7 @@ import { writeAPI, scraperTargetsApi, } from 'src/utils/api' + import { Telegraf, WritePrecision, @@ -68,19 +69,6 @@ export const setSetupParams = async ( } } -export const signin = async (params: { - username: string - password: string -}): Promise => { - const {username, password} = params - try { - await baseAPI.signinPost({auth: {username, password}}) - } catch (error) { - console.error('Sign in has failed', error) - throw error - } -} - export const trySources = async (): Promise => { try { await sourcesAPI.sourcesGet('') diff --git a/ui/src/onboarding/components/SigninForm.tsx b/ui/src/onboarding/components/SigninForm.tsx index d4129c507c..960458944e 100644 --- a/ui/src/onboarding/components/SigninForm.tsx +++ b/ui/src/onboarding/components/SigninForm.tsx @@ -20,7 +20,7 @@ import { } from 'src/clockface' // APIs -import {signin} from 'src/onboarding/apis' +import {client} from 'src/utils/api' // Actions import {notify as notifyAction} from 'src/shared/actions/notifications' @@ -107,7 +107,7 @@ class SigninForm extends PureComponent { const {username, password} = this.state try { - await signin({username, password}) + await client.auth.signin(username, password) this.handleRedirect() } catch (error) { const message = get(error, 'response.data.msg', '') diff --git a/ui/src/utils/api.ts b/ui/src/utils/api.ts index 0e3a1a3743..c0d30ddc8f 100644 --- a/ui/src/utils/api.ts +++ b/ui/src/utils/api.ts @@ -18,8 +18,12 @@ import { LabelsApi, } from 'src/api' +import Client from '@influxdata/influx' + const basePath = '/api/v2' +export const client = new Client(basePath) + export const baseAPI = new DefaultApi({basePath}) export const viewsAPI = new ViewsApi({basePath}) export const taskAPI = new TasksApi({basePath})