Skip to content

Commit

Permalink
Add some missing 'await's. Most are just waiting for DB to store.
Browse files Browse the repository at this point in the history
  • Loading branch information
Misterblue committed Feb 5, 2021
1 parent 9fa357a commit 5b86982
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Entities/Places.ts
Expand Up @@ -60,6 +60,7 @@ export const Places = {
newPlace.path = '/0,0,0/0,0,0,1';
newPlace.whenCreated = new Date();
const APItoken = await Tokens.createToken(pAccountId, [ TokenScope.PLACE ], -1);
await Tokens.addToken(APItoken); // put token into DB
newPlace.currentAPIKeyTokenId = APItoken.id;
return newPlace;
},
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Tokens.ts
Expand Up @@ -78,7 +78,7 @@ export const Tokens = {
break;
case -1:
// Expiration is infinite
aToken.expirationTime = new Date(2399, 1);
aToken.expirationTime = new Date(2399, 12);
break;
default:
// There is a specification of some hours to expire
Expand Down
2 changes: 1 addition & 1 deletion src/route-tools/Util.ts
Expand Up @@ -268,7 +268,7 @@ export async function buildPlaceInfoSmall(pPlace: PlaceEntity, pDomain?: DomainE
'placeId': pPlace.id,
'id': pPlace.id,
'name': pPlace.name,
'address': Places.getAddressString(pPlace),
'address': await Places.getAddressString(pPlace),
'path': pPlace.path,
'description': pPlace.description,
'maturity': pPlace.maturity ?? Maturity.UNRATED,
Expand Down
1 change: 1 addition & 0 deletions src/route-tools/middleware.ts
Expand Up @@ -164,6 +164,7 @@ export const verifyDomainAccess: RequestHandler = async (req: Request, resp: Res
// Auth token not available. See if APIKey does the trick
if (req.vDomain.apiKey === req.vDomainAPIKey) {
// APIKEY matches so create a fake AuthToken that works with checkAccessToEntity
// Note that this token does not get written to the DB
req.vAuthToken = await Tokens.createToken(req.vDomainAPIKey, [ TokenScope.DOMAIN ], 1);
verified = true;
};
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/v1/token/new.ts
Expand Up @@ -33,7 +33,7 @@ const procPostTokenNew: RequestHandler = async (req: Request, resp: Response, ne
};
if (TokenScope.KnownScope(scope)) {
const tokenInfo = await Tokens.createToken(req.vAuthAccount.id, [ scope ]);
Tokens.addToken(tokenInfo);
await Tokens.addToken(tokenInfo);
req.vRestResp.Data = {
'token': tokenInfo.token,
'token_id': tokenInfo.id,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/oauth/token.ts
Expand Up @@ -98,7 +98,7 @@ const procPostOauthToken: RequestHandler = async (req: Request, resp: Response,
if (requestingAccount && refreshToken.accountId === requestingAccount.id) {
// refresh token has not expired and requestor is owner of the token so make new
const newToken = await Tokens.createToken(req.vAuthAccount.id, refreshToken.scope);
Tokens.addToken(newToken);
await Tokens.addToken(newToken);
respBody = buildOAuthResponseBody(requestingAccount, newToken);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/user/tokens/new.ts
Expand Up @@ -28,7 +28,7 @@ const procGetUserTokensNew: RequestHandler = async (req: Request, resp: Response
const forDomainServer = req.query.for_domain_server;
const scope = forDomainServer ? TokenScope.DOMAIN : TokenScope.OWNER;
const tokenInfo = await Tokens.createToken(req.vAuthAccount.id, [ scope ]);
Tokens.addToken(tokenInfo);
await Tokens.addToken(tokenInfo);

const body = `<center><h2>Your domain's access token is ${tokenInfo.token}</h2></center>`;
resp.setHeader('content-type', 'text/html');
Expand Down

0 comments on commit 5b86982

Please sign in to comment.