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