1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Auth flow

This commit is contained in:
Pedro Silva 2023-02-24 09:46:05 +00:00
parent 9474d24908
commit 655b235b76
3 changed files with 10 additions and 5 deletions

View file

@ -23,6 +23,7 @@ class PublicAPIClient {
) )
} }
this.host = `${env.BUDIBASE_HOST}/api/public/v1` this.host = `${env.BUDIBASE_HOST}/api/public/v1`
this.appId = appId this.appId = appId
} }
@ -32,6 +33,8 @@ class PublicAPIClient {
setApiKey(apiKey: string) { setApiKey(apiKey: string) {
this.apiKey = apiKey this.apiKey = apiKey
process.env.BUDIBASE_PUBLIC_API_KEY = apiKey
this.host = `${env.BUDIBASE_HOST}/api/public/v1`
} }
apiCall = apiCall =

View file

@ -1,16 +1,16 @@
import { Response } from "node-fetch" import { Response } from "node-fetch"
import PublicAPIClient from "./PublicAPIClient" import AccountsAPIClient from "./accountsAPIClient"
import { ApiKeyResponse } from "../fixtures/types/apiKeyResponse" import { ApiKeyResponse } from "../fixtures/types/apiKeyResponse"
export default class AuthApi { export default class AuthApi {
api: PublicAPIClient api: AccountsAPIClient
constructor(apiClient: PublicAPIClient) { constructor(apiClient: AccountsAPIClient) {
this.api = apiClient this.api = apiClient
} }
async loginAsAdmin(): Promise<[Response, any]> { async loginAsAdmin(): Promise<[Response, any]> {
const response = await this.api.post(`/global/auth/default/login`, { const response = await this.api.post(`/auth/login`, {
body: { body: {
username: process.env.BB_ADMIN_USER_EMAIL, username: process.env.BB_ADMIN_USER_EMAIL,
password: process.env.BB_ADMIN_USER_PASSWORD, password: process.env.BB_ADMIN_USER_PASSWORD,
@ -22,7 +22,7 @@ export default class AuthApi {
} }
async login(email: String, password: String): Promise<[Response, any]> { async login(email: String, password: String): Promise<[Response, any]> {
const response = await this.api.post(`/global/auth/default/login`, { const response = await this.api.post(`/auth/login`, {
body: { body: {
username: email, username: email,
password: password, password: password,

View file

@ -11,6 +11,8 @@ describe("Public API - /users endpoints", () => {
beforeAll(async () => { beforeAll(async () => {
await config.beforeAll() await config.beforeAll()
await config.setupAccountAndTenant()
await config.setApiKey()
const [_, user] = await config.users.seed() const [_, user] = await config.users.seed()
config.context = user config.context = user
}) })