Skip to content

Commit

Permalink
Rework api/auth interface
Browse files Browse the repository at this point in the history
PR-URL: metarhia#81
  • Loading branch information
tshemsedinov committed Feb 4, 2021
1 parent d166cb6 commit 4249c1a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
5 changes: 0 additions & 5 deletions application/api/auth.1/register.js

This file was deleted.

7 changes: 0 additions & 7 deletions application/api/auth.1/status.js

This file was deleted.

9 changes: 9 additions & 0 deletions application/api/auth.2/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
({
access: 'public',
async method({ login, password, fullName }) => {
const hash = await metarhia.metautil.hashPassword(password);
await application.auth.registerUser(login, hash, fullName);
const token = await context.client.startSession();
return { status: 'success', token };
}
});
8 changes: 8 additions & 0 deletions application/api/auth.2/restore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
({
access: 'public',
method: async ({ token }) => {
const success = await context.client.restoreSession(token);
const status = success ? 'logged' : 'not logged';
return { status };
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
method: async ({ login, password }) => {
const user = await application.auth.getUser(login);
const hash = user ? user.password : undefined;
const valid = await application.security.validatePassword(password, hash);
const valid = await metarhia.metautil.validatePassword(password, hash);
if (!user || !valid) throw new Error('Incorrect login or password');
console.log(`Logged user: ${login}`);
return { result: 'success', userId: user.id };
const token = await context.client.startSession(user.systemUserId);
return { status: 'logged', token };
}
});

0 comments on commit 4249c1a

Please sign in to comment.