Skip to content

Commit

Permalink
fix: login auth flow
Browse files Browse the repository at this point in the history
- removes login tokens, replaced with csrf cookies
  • Loading branch information
zSoulweaver committed Nov 1, 2024
1 parent 50dc0bb commit 9a04478
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
13 changes: 3 additions & 10 deletions src/endpoints/authentication/authentication.endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { cast } from '@deepkit/type'
import type { ChannelAuthorizationRequestParams } from 'pusher-js/types/src/core/auth/options'
import { BaseEndpoint } from '../endpoint.base'
import type { TokensResponse } from './dto/tokens.response'
import type { LoginErrorResponse, LoginResponse } from './dto/login.response'
import type { UserResponse } from './dto/user.response'
import type { PusherAuthenticationResponse } from './dto/pusher-authentication.response'
Expand All @@ -15,25 +14,19 @@ import { buildBody } from '@/utils/build-body'
* @category Endpoints
*/
export class AuthenticationEndpoint extends BaseEndpoint {
public async getTokens() {
const response = await this._apiClient.callKickApi({ endpoint: 'kick-token-provider' })
if (response.status !== 200)
throw new KientApiError('Failed to retrieve pre-login tokens', { cause: response })

return cast<TokensResponse>(response.body)
public async getCsrfHeaders() {
await this._apiClient.callKickApi({ endpoint: 'sanctum/csrf' })
}

public async login(credentials: LoginCredentials, kickAuthHeader: string = '') {
this._apiClient.setKickAuthHeader(kickAuthHeader)
const tokens = await this.getTokens()
await this.getCsrfHeaders()

const body = buildBody<LoginInput>({
email: credentials.email,
password: credentials.password,
one_time_password: credentials.otc,
isMobileRequest: true,
[tokens.nameFieldName]: '',
[tokens.validFromFieldName]: tokens.encryptedValidFrom,
})
const response = await this._apiClient.callKickApi({
endpoint: 'mobile/login',
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/authentication/dto/login.input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface LoginInput extends Record<string, any> {
export interface LoginInput {
email: string
password: string
one_time_password?: string | number
Expand Down
7 changes: 0 additions & 7 deletions src/endpoints/authentication/dto/tokens.response.ts

This file was deleted.

0 comments on commit 9a04478

Please sign in to comment.