mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-24 00:43:09 +02:00
Refactoring
This commit is contained in:
parent
67dacb7725
commit
2f0b75a882
1 changed files with 7 additions and 8 deletions
|
@ -3,10 +3,9 @@ import { default as User, IUser } from '../../models/user';
|
||||||
import AccessToken from '../../models/access-token';
|
import AccessToken from '../../models/access-token';
|
||||||
import isNativeToken from './common/is-native-token';
|
import isNativeToken from './common/is-native-token';
|
||||||
|
|
||||||
export default (token: string) => new Promise<[IUser, IApp]>(async (resolve, reject) => {
|
export default async (token: string): Promise<[IUser, IApp]> => {
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
resolve([null, null]);
|
return [null, null];
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNativeToken(token)) {
|
if (isNativeToken(token)) {
|
||||||
|
@ -15,17 +14,17 @@ export default (token: string) => new Promise<[IUser, IApp]>(async (resolve, rej
|
||||||
.findOne({ token });
|
.findOne({ token });
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
return reject('user not found');
|
throw 'user not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve([user, null]);
|
return [user, null];
|
||||||
} else {
|
} else {
|
||||||
const accessToken = await AccessToken.findOne({
|
const accessToken = await AccessToken.findOne({
|
||||||
hash: token.toLowerCase()
|
hash: token.toLowerCase()
|
||||||
});
|
});
|
||||||
|
|
||||||
if (accessToken === null) {
|
if (accessToken === null) {
|
||||||
return reject('invalid signature');
|
throw 'invalid signature';
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = await App
|
const app = await App
|
||||||
|
@ -34,6 +33,6 @@ export default (token: string) => new Promise<[IUser, IApp]>(async (resolve, rej
|
||||||
const user = await User
|
const user = await User
|
||||||
.findOne({ _id: accessToken.userId });
|
.findOne({ _id: accessToken.userId });
|
||||||
|
|
||||||
resolve([user, app]);
|
return [user, app];
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
Loading…
Reference in a new issue