Skip to content

Commit

Permalink
Merge pull request #58 from silverlogic/update-auth-endpoint-default-…
Browse files Browse the repository at this point in the history
…path

update auth endpoint url path to match baseapp-django-v3
  • Loading branch information
Janekk authored Oct 2, 2023
2 parents 4575eeb + 6bab71f commit 97fabc9
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions apps/docs/pages/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Auth() {

const mockForSuccessAndLogIn = (e: any) => {
e.preventDefault()
axiosMock.onPost('/login').reply(
axiosMock.onPost('/auth/login').reply(
(_config) =>
new Promise((resolve, _reject) => {
setTimeout(() => {
Expand All @@ -29,7 +29,7 @@ export default function Auth() {

const mockForErrorAndLogIn = () => {
axiosMock
.onPost('/login')
.onPost('/auth/login')
.reply(400, { email: ['Testing Api Error'], password: ['Wrong Password'] })
form.handleSubmit()
}
Expand Down
6 changes: 6 additions & 0 deletions packages/authentication/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @baseapp-frontend/authentication

## 1.1.3

### Patch Changes

- update auth endpoint url path to match baseapp-django-v3. The default login path is `/auth/login` for both SimpleToken and JWT auth

## 1.1.2

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const axiosMock = new MockAdapter(axios)

describe('useLogin', () => {
test('should run onSuccess', async () => {
axiosMock.onPost('/auth').reply(200, {
axiosMock.onPost('/auth/login').reply(200, {
token: 'fake token',
})
cookiesMock.set.mockImplementation((cookieName: string) => cookieName)
Expand Down
3 changes: 1 addition & 2 deletions packages/authentication/modules/access/useLogin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ const useLogin = ({
})

const mutation = useMutation({
mutationFn: (data: ILoginRequest) =>
tokenType === TokenTypes.jwt ? ApiClass.login(data) : ApiClass.simpleTokenLogin(data),
mutationFn: (data: ILoginRequest) => ApiClass.login(data),
...loginOptions, // needs to be placed bellow all overridable options
onError: (err, variables, context) => {
loginOptions?.onError?.(err, variables, context)
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/modules/access/useLogin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UseMutationOptions } from '@tanstack/react-query'
import AuthApi from '../../../services/auth'
import { ICookieName, ILoginMfaRequest, ILoginRequest, LoginResponse } from '../../../types/auth'

type ApiClass = Pick<typeof AuthApi, 'login' | 'simpleTokenLogin'>
type ApiClass = Pick<typeof AuthApi, 'login'>

export interface IUseLogin extends ICookieName {
// TODO: refactor types
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@baseapp-frontend/authentication",
"description": "Authentication modules.",
"version": "1.1.2",
"version": "1.1.3",
"main": "./dist/index.ts",
"module": "./dist/index.mjs",
"scripts": {
Expand Down
4 changes: 0 additions & 4 deletions packages/authentication/services/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import {

export default class AuthApi {
static login({ email, password }: ILoginRequest): Promise<LoginResponse> {
return axios.post(`/auth`, { email, password })
}

static simpleTokenLogin({ email, password }: ILoginRequest): Promise<LoginResponse> {
return axios.post(`/auth/login`, { email, password })
}

Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/services/mfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class MfaApi {
}

static loginStep2(data: ILoginMfaRequest): Promise<ILoginSimpleTokenResponse> {
return axios.post('/login/code', data)
return axios.post('/auth/login/code', data)
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @baseapp-frontend/core

## 2.7.3

### Patch Changes

- update auth endpoint url path to match baseapp-django-v3. The default login path is `/auth/login` for both SimpleToken and JWT auth

## 2.7.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@baseapp-frontend/core",
"version": "2.7.2",
"version": "2.7.3",
"description": "Core utilities.",
"main": "./src/index.tsx",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/mfa/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export default class MfaApi {
}

static loginStep2(data: ILoginMfaRequest): Promise<AxiosResponse<ILoginResponse>> {
return axios.post('/login/code', data)
return axios.post('/auth/login/code', data)
}
}

0 comments on commit 97fabc9

Please sign in to comment.