mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Improve device creation on login/register
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { LoginOutput } from '@colanode/core';
|
||||
import { EmailLoginInput, LoginOutput } from '@colanode/core';
|
||||
|
||||
import { app } from 'electron';
|
||||
|
||||
import { databaseService } from '@/main/data/database-service';
|
||||
import { MutationHandler } from '@/main/types';
|
||||
@@ -26,12 +28,16 @@ export class EmailLoginMutationHandler
|
||||
}
|
||||
|
||||
try {
|
||||
const emailLoginInput: EmailLoginInput = {
|
||||
email: input.email,
|
||||
password: input.password,
|
||||
platform: process.platform,
|
||||
version: app.getVersion(),
|
||||
};
|
||||
|
||||
const { data } = await httpClient.post<LoginOutput>(
|
||||
'/v1/accounts/emails/login',
|
||||
{
|
||||
email: input.email,
|
||||
password: input.password,
|
||||
},
|
||||
emailLoginInput,
|
||||
{
|
||||
domain: server.domain,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { LoginOutput } from '@colanode/core';
|
||||
import { EmailRegisterInput, LoginOutput } from '@colanode/core';
|
||||
|
||||
import { app } from 'electron';
|
||||
|
||||
import { databaseService } from '@/main/data/database-service';
|
||||
import { MutationHandler } from '@/main/types';
|
||||
@@ -28,13 +30,17 @@ export class EmailRegisterMutationHandler
|
||||
}
|
||||
|
||||
try {
|
||||
const emailRegisterInput: EmailRegisterInput = {
|
||||
name: input.name,
|
||||
email: input.email,
|
||||
password: input.password,
|
||||
platform: process.platform,
|
||||
version: app.getVersion(),
|
||||
};
|
||||
|
||||
const { data } = await httpClient.post<LoginOutput>(
|
||||
'/v1/accounts/emails/register',
|
||||
{
|
||||
name: input.name,
|
||||
email: input.email,
|
||||
password: input.password,
|
||||
},
|
||||
emailRegisterInput,
|
||||
{
|
||||
domain: server.domain,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { LoginOutput } from '@colanode/core';
|
||||
import { EmailVerifyInput, LoginOutput } from '@colanode/core';
|
||||
|
||||
import { app } from 'electron';
|
||||
|
||||
import { databaseService } from '@/main/data/database-service';
|
||||
import { MutationHandler } from '@/main/types';
|
||||
@@ -26,12 +28,16 @@ export class EmailVerifyMutationHandler
|
||||
}
|
||||
|
||||
try {
|
||||
const emailVerifyInput: EmailVerifyInput = {
|
||||
id: input.id,
|
||||
otp: input.otp,
|
||||
platform: process.platform,
|
||||
version: app.getVersion(),
|
||||
};
|
||||
|
||||
const { data } = await httpClient.post<LoginOutput>(
|
||||
'/v1/accounts/emails/verify',
|
||||
{
|
||||
id: input.id,
|
||||
otp: input.otp,
|
||||
},
|
||||
emailVerifyInput,
|
||||
{
|
||||
domain: server.domain,
|
||||
}
|
||||
|
||||
@@ -68,9 +68,10 @@ export const emailLoginHandler = async (
|
||||
});
|
||||
}
|
||||
|
||||
const output = await accountService.buildLoginSuccessOutput(
|
||||
account,
|
||||
res.locals.ip
|
||||
);
|
||||
const output = await accountService.buildLoginSuccessOutput(account, {
|
||||
ip: res.locals.ip,
|
||||
platform: input.platform,
|
||||
version: input.version,
|
||||
});
|
||||
return ResponseBuilder.success(res, output);
|
||||
};
|
||||
|
||||
@@ -113,9 +113,10 @@ export const emailRegisterHandler = async (
|
||||
});
|
||||
}
|
||||
|
||||
const output = await accountService.buildLoginSuccessOutput(
|
||||
account,
|
||||
res.locals.ip
|
||||
);
|
||||
const output = await accountService.buildLoginSuccessOutput(account, {
|
||||
ip: res.locals.ip,
|
||||
platform: input.platform,
|
||||
version: input.version,
|
||||
});
|
||||
return ResponseBuilder.success(res, output);
|
||||
};
|
||||
|
||||
@@ -32,9 +32,10 @@ export const emailVerifyHandler = async (req: Request, res: Response) => {
|
||||
});
|
||||
}
|
||||
|
||||
const output = await accountService.buildLoginSuccessOutput(
|
||||
account,
|
||||
res.locals.ip
|
||||
);
|
||||
const output = await accountService.buildLoginSuccessOutput(account, {
|
||||
ip: res.locals.ip,
|
||||
platform: input.platform,
|
||||
version: input.version,
|
||||
});
|
||||
return ResponseBuilder.success(res, output);
|
||||
};
|
||||
|
||||
@@ -78,7 +78,11 @@ export const loginWithGoogleHandler = async (
|
||||
|
||||
const output = await accountService.buildLoginSuccessOutput(
|
||||
existingAccount,
|
||||
res.locals.ip
|
||||
{
|
||||
ip: res.locals.ip,
|
||||
platform: input.platform,
|
||||
version: input.version,
|
||||
}
|
||||
);
|
||||
return ResponseBuilder.success(res, output);
|
||||
}
|
||||
@@ -104,9 +108,10 @@ export const loginWithGoogleHandler = async (
|
||||
});
|
||||
}
|
||||
|
||||
const output = await accountService.buildLoginSuccessOutput(
|
||||
newAccount,
|
||||
res.locals.ip
|
||||
);
|
||||
const output = await accountService.buildLoginSuccessOutput(newAccount, {
|
||||
ip: res.locals.ip,
|
||||
platform: input.platform,
|
||||
version: input.version,
|
||||
});
|
||||
return ResponseBuilder.success(res, output);
|
||||
};
|
||||
|
||||
@@ -23,10 +23,16 @@ import { emailService } from '@/services/email-service';
|
||||
const OTP_DIGITS = '0123456789';
|
||||
const OTP_LENGTH = 6;
|
||||
|
||||
interface DeviceMetadata {
|
||||
ip: string | undefined;
|
||||
platform: string;
|
||||
version: string;
|
||||
}
|
||||
|
||||
class AccountService {
|
||||
public async buildLoginSuccessOutput(
|
||||
account: SelectAccount,
|
||||
ip: string | undefined
|
||||
metadata: DeviceMetadata
|
||||
): Promise<LoginSuccessOutput> {
|
||||
const users = await database
|
||||
.selectFrom('users')
|
||||
@@ -81,9 +87,10 @@ class AccountService {
|
||||
token_salt: salt,
|
||||
token_generated_at: new Date(),
|
||||
type: 1,
|
||||
ip,
|
||||
ip: metadata.ip,
|
||||
platform: metadata.platform,
|
||||
version: metadata.version,
|
||||
created_at: new Date(),
|
||||
version: '0.1.0',
|
||||
})
|
||||
.returningAll()
|
||||
.executeTakeFirst();
|
||||
|
||||
Reference in New Issue
Block a user