login service
This commit is contained in:
parent
544a134eb3
commit
ba9b4d5ef3
4 changed files with 12 additions and 12 deletions
|
|
@ -29,6 +29,8 @@ class ServicesProvider {
|
|||
|
||||
const LoginServiceProvider = require('../services/loginService');
|
||||
const loginService = new LoginServiceProvider({
|
||||
models,
|
||||
errors,
|
||||
nostrService,
|
||||
invitesService,
|
||||
}).provide();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
const uuid = require('uuid');
|
||||
|
||||
const models = require('../models');
|
||||
|
||||
const errors = require('../errors');
|
||||
|
||||
class LoginServiceProvider {
|
||||
constructor({ nostrService, invitesService }) {
|
||||
constructor({ models, errors, nostrService, invitesService }) {
|
||||
this.models = models;
|
||||
this.errors = errors;
|
||||
this.nostrService = nostrService;
|
||||
this.invitesService = invitesService;
|
||||
}
|
||||
|
|
@ -14,7 +12,7 @@ class LoginServiceProvider {
|
|||
const createLoginChallenge = async () => {
|
||||
const nostrChallenge = await this.nostrService.createNostrChallenge();
|
||||
|
||||
return await models.LoginChallengeCreated.create({
|
||||
return await this.models.LoginChallengeCreated.create({
|
||||
uuid: uuid.v7(),
|
||||
nostr_challenge_uuid: nostrChallenge.uuid,
|
||||
created_at: new Date().toISOString(),
|
||||
|
|
@ -28,7 +26,7 @@ class LoginServiceProvider {
|
|||
const challenge = challengeTag[1];
|
||||
|
||||
if (await this.nostrService.hasNostrChallengeBeenCompleted(challenge)) {
|
||||
throw new errors.AlreadyUsedError(
|
||||
throw new this.errors.AlreadyUsedError(
|
||||
'This challenge has already been used.'
|
||||
);
|
||||
}
|
||||
|
|
@ -42,13 +40,13 @@ class LoginServiceProvider {
|
|||
))
|
||||
) {
|
||||
console.log('helo4');
|
||||
throw new errors.ForbiddenError(
|
||||
throw new this.errors.ForbiddenError(
|
||||
`Public key ${completedNostrChallenge.public_key} is not authorized.`
|
||||
);
|
||||
}
|
||||
|
||||
const completedLoginChallenge =
|
||||
await models.LoginChallengeCompleted.create({
|
||||
await this.models.LoginChallengeCompleted.create({
|
||||
uuid: uuid.v7(),
|
||||
nostr_challenge_completed_uuid: completedNostrChallenge.uuid,
|
||||
public_key: completedNostrChallenge.public_key,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ class NostrServiceProvider {
|
|||
const challenge = challengeTag[1];
|
||||
|
||||
if (!(await isNostrChallengeFresh(challenge))) {
|
||||
throw this.errors.ExpiredError('Challenge expired, request new one.');
|
||||
throw new this.errors.ExpiredError(
|
||||
'Challenge expired, request new one.'
|
||||
);
|
||||
}
|
||||
|
||||
if (await hasNostrChallengeBeenCompleted(challenge)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue