Skip to content

Commit c54f9d0

Browse files
committed
replaced iam service with authentication service
1 parent 245ba3a commit c54f9d0

File tree

11 files changed

+16
-103
lines changed

11 files changed

+16
-103
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ to start with Technical and let the project naturally evolve into one of the oth
9292

9393
### File Naming
9494

95-
You might notice how each file in the backend is postfixed with its architectural type(e.g. `iam.service.ts`). This allows
95+
You might notice how each file in the backend is postfixed with its architectural type(e.g. `authentication.service.ts`). This allows
9696
us to easily reorganize the folder structure to suite a different architecture pattern if the domain becomes more complex.
9797

9898
For example, if you want to group folders by domain(DDD), you simply drag and drop all related files to that folder.

src/hooks.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const apiClient: Handle = async ({ event, resolve }) => {
1818

1919
/* ----------------------------- Auth functions ----------------------------- */
2020
async function getAuthedUser() {
21-
const { data } = await api.iam.me.$get().then(parseApiResponse)
21+
const { data } = await api.auth.me.$get().then(parseApiResponse)
2222
return data && data.user;
2323
}
2424

2525
async function getAuthedUserOrThrow(redirectTo = '/') {
26-
const { data } = await api.iam.me.$get().then(parseApiResponse);
26+
const { data } = await api.auth.me.$get().then(parseApiResponse);
2727
if (!data || !data.user) throw redirect(StatusCodes.TEMPORARY_REDIRECT, redirectTo);
2828
return data?.user;
2929
}

src/lib/server/api/common/types/controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import type { BlankSchema } from "hono/types";
44

55
export abstract class Controler {
66
protected readonly controller: Hono<HonoTypes, BlankSchema, '/'>;
7+
78
constructor() {
89
this.controller = new Hono();
910
}
11+
1012
abstract routes(): Hono<HonoTypes, BlankSchema, '/'>;
1113
}

src/lib/server/api/controllers/iam.controller.ts renamed to src/lib/server/api/controllers/authentication.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { loginDto } from '../dtos/login.dto';
1313
import { verifyLoginDto } from '../dtos/verify-login.dto';
1414

1515
@injectable()
16-
export class IamController extends Controler {
16+
export class AuthenticationController extends Controler {
1717
constructor(
1818
@inject(AuthenticationService) private authenticationService: AuthenticationService,
1919
@inject(EmailVerificationService) private emailVerificationService: EmailVerificationService,

src/lib/server/api/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'reflect-metadata';
22
import { Hono } from 'hono';
33
import { hc } from 'hono/client';
44
import { container } from 'tsyringe';
5-
import { IamController } from './controllers/iam.controller';
5+
import { AuthenticationController } from './controllers/authentication.controller';
66
import { config } from './common/config';
77
import { validateAuthSession, verifyOrigin } from './middlewares/auth.middleware';
88
import { AuthCleanupJobs } from './jobs/auth-cleanup.job';
@@ -20,8 +20,7 @@ app.use(verifyOrigin).use(validateAuthSession);
2020
/* -------------------------------------------------------------------------- */
2121
/* Routes */
2222
/* -------------------------------------------------------------------------- */
23-
const routes = app
24-
.route('/iam', container.resolve(IamController).routes())
23+
const routes = app.route('/auth', container.resolve(AuthenticationController).routes());
2524

2625
/* -------------------------------------------------------------------------- */
2726
/* Cron Jobs */
@@ -35,7 +34,3 @@ container.resolve(AuthCleanupJobs).deleteStaleLoginRequests();
3534
const rpc = hc<typeof routes>(config.api.origin);
3635
export type ApiClient = typeof rpc;
3736
export type ApiRoutes = typeof routes;
38-
39-
40-
41-

src/lib/server/api/services/authentication.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,4 @@ export class AuthenticationService {
7373
return loginRequest
7474
})
7575
}
76-
77-
78-
79-
8076
}

src/lib/server/api/services/iam.service.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/lib/server/api/tests/login-requests.service.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { LoginRequestsRepository } from '../repositories/login-requests.reposito
77
import { container } from 'tsyringe';
88
import { LuciaService } from '../services/lucia.service';
99
import { DrizzleService } from '../services/drizzle.service';
10-
import { IamService } from '../services/iam.service';
10+
import { AuthenticationService } from '../services/authentication.service';
1111

1212
describe('LoginRequestService', () => {
13-
let service: IamService;
13+
let service: AuthenticationService;
1414
let tokensService = vi.mocked(TokensService.prototype)
1515
let mailerService = vi.mocked(MailerService.prototype);
1616
let usersRepository = vi.mocked(UsersRepository.prototype);
@@ -26,7 +26,7 @@ describe('LoginRequestService', () => {
2626
.register(LoginRequestsRepository, { useValue: loginRequestsRepository })
2727
.register(LuciaService, { useValue: luciaService })
2828
.register(DrizzleService, { useValue: drizzleService })
29-
.resolve(IamService);
29+
.resolve(AuthenticationService);
3030
});
3131

3232
afterAll(() => {

src/routes/(app)/+page.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const load = async ({ locals }) => {
88

99
export const actions = {
1010
logout: async ({ locals }) => {
11-
await locals.api.iam.logout.$post()
11+
await locals.api.auth.logout.$post()
1212
redirect(StatusCodes.SEE_OTHER, '/register')
1313
}
1414
}

src/routes/(app)/settings/account/+page.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export const actions = {
1717
updateEmail: async ({ request, locals }) => {
1818
const updateEmailForm = await superValidate(request, zod(updateEmailFormSchema));
1919
if (!updateEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { updateEmailForm })
20-
const { error } = await locals.api.iam.email.$patch({ json: updateEmailForm.data }).then(locals.parseApiResponse);
20+
const { error } = await locals.api.auth.email.$patch({ json: updateEmailForm.data }).then(locals.parseApiResponse);
2121
if (error) return setError(updateEmailForm, 'email', error);
2222
return { updateEmailForm }
2323
},
2424
verifyEmail: async ({ request, locals }) => {
2525
const verifyEmailForm = await superValidate(request, zod(verifyEmailFormSchema));
2626
console.log(verifyEmailForm)
2727
if (!verifyEmailForm.valid) return fail(StatusCodes.BAD_REQUEST, { verifyEmailForm })
28-
const { error } = await locals.api.iam.email.verification.$post({ json: verifyEmailForm.data }).then(locals.parseApiResponse);
28+
const { error } = await locals.api.auth.email.verification.$post({ json: verifyEmailForm.data }).then(locals.parseApiResponse);
2929
if (error) return setError(verifyEmailForm, 'token', error);
3030
return { verifyEmailForm }
3131
}

0 commit comments

Comments
 (0)