injext client

This commit is contained in:
john 2025-05-20 11:47:16 +02:00
parent bc97d009ae
commit 0cbcab6597
5 changed files with 38 additions and 34 deletions

View file

@ -1,14 +1,14 @@
import { dispatchMessage } from '../messageBus/messageBus.ts'
import client from '../api/client.ts'
import { ProblemDetails } from '../../types'
import { SignupCode } from './signupCode.ts'
import { getCookie } from './cookies.ts'
import { ApiClient } from '../api/client.ts'
export class AuthService {
constructor() {}
constructor(private readonly client: ApiClient) {}
async login(username: string, password: string) {
const res = await client.POST('/auth/login', {
const res = await this.client.POST('/auth/login', {
body: { username, password },
credentials: 'include',
})
@ -21,7 +21,7 @@ export class AuthService {
}
async signup(username: string, password: string, signupCode: string) {
const res = await client.POST('/auth/register', {
const res = await this.client.POST('/auth/register', {
body: { username, password, signupCode, email: null },
credentials: 'include',
})
@ -35,13 +35,13 @@ export class AuthService {
}
async logout() {
await client.DELETE('/auth/session', { credentials: 'include' })
await this.client.DELETE('/auth/session', { credentials: 'include' })
dispatchMessage('auth:logged-out', null)
}
async createSignupCode(code: string, email: string, name: string) {
const res = await client.POST('/auth/signup-codes', {
const res = await this.client.POST('/auth/signup-codes', {
body: { code, email, name },
credentials: 'include',
})
@ -53,7 +53,7 @@ export class AuthService {
}
async listSignupCodes() {
const res = await client.GET('/auth/signup-codes', {
const res = await this.client.GET('/auth/signup-codes', {
credentials: 'include',
})
@ -70,7 +70,7 @@ export class AuthService {
return null
}
await client.GET(`/auth/user/{userId}`, {
await this.client.GET(`/auth/user/{userId}`, {
params: {
path: { userId },
},