Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Integrate API, Client and backoffice auth #130

Merged
merged 2 commits into from
Dec 3, 2024

Conversation

alepefe
Copy link
Collaborator

@alepefe alepefe commented Dec 2, 2024

This pull request includes significant changes to add backoffice session management and improve authentication functionality. The most important changes include adding new dependencies, modifying authentication logic to handle backoffice sessions, and renaming the admin module to backoffice.

Backoffice Session Management:

Dependency Additions:

Authentication Enhancements:

Module Renaming:

  • Renamed admin module to backoffice and updated related files and imports. [1] [2] [3]

Configuration Updates:

Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tnc-blue-carbon-cost-tool-ghps ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 2, 2024 2:08pm

): Promise<BackOfficeSession> {
// We replicate what adminjs does by default using postgres as session storage (the default in memory session storage is not production ready)
// This implementation is not compatible with many devices per user
await this.backOfficeSessionRepository
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Maybe it would be nice to move this to some private method like:
clearExistingSessionAdminSession or smth like that.

It also feels weird to not declaratively know what would happen if the query does not target any row but I guess we can live with that as long as we know how the underlying query works

@@ -19,6 +19,26 @@ import { JwtConfigHandler } from '@api/modules/config/auth-config.handler';
resolveConfigPath(`shared/config/.env.${process.env.NODE_ENV}`),
resolveConfigPath(`shared/config/.env`),
],
validate(config) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -26,7 +26,7 @@ export class CustomProject {
@PrimaryGeneratedColumn("uuid")
id?: string;

@Column({ type: "varchar", name: "project_name" })
@Column({ name: "project_name", type: "varchar" })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOC triggered!!

),
);
const backofficeSession: BackOfficeSession = {
sid: uid.sync(24),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason you consider pg's gen_random_uuid() is not safe enough crypto-wise?
According to the docs it should be, unless the instance runs out of some resource and it falls back to not-very-oosp method to generate it

If no specific reason, we might offload this here, and also avoid using a lib that was last released 7 years ago

@@ -31,6 +40,8 @@ export class AuthenticationService {
private readonly commandBus: CommandBus,
private readonly eventBus: EventBus,
private readonly passwordManager: PasswordManager,
@InjectRepository(BackOfficeSession)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor detail:

We might inject the back office session repo only in the back office service, and move this service around. it might be more clean and would also allow us to encapsulate potential helper methods that we might need in the future, coupling back office related logic and data retrieval in a single point

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it when we need to create the back office service and move forward now.

override async handleLogout({res}: {res: Response}) {
// Remove auth cookies
res.setHeader('Set-Cookie', [
`backoffice=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; HttpOnly`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't work if we just remove the cookie/cookies altogether instead of rewriting this value?

Copy link
Collaborator

@alexeh alexeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job @alepefe thanks.

I have left some minor details, but not strong opinions about. Feel free to consider or ignore them altogether.

I am just particularly curious about this tho:
https://github.com/Vizzuality/tnc-blue-carbon-cost-tool/pull/130/files#r1867154414

I haven't had the time to properly run and test this to be honest, let's just iterate if somehting goes south. Let me know what your plan is before pushing this through!

Copy link
Member

@andresgnlez andresgnlez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Good job!

@alepefe alepefe merged commit 9e7f943 into dev Dec 3, 2024
4 checks passed
@alepefe alepefe deleted the feat/adminjs-integration branch December 3, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants