-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v1.0.0' into develop
- Loading branch information
Showing
14 changed files
with
57 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { getHeaderToken } from '../src' | ||
import { getHeaderToken } from '../src'; | ||
|
||
test('should get token', () => { | ||
expect( | ||
getHeaderToken({ headers: { authorization: 'xxx' } } as any) | ||
).toBe(null); | ||
expect(getHeaderToken({ headers: { authorization: 'xxx' } } as any)).toBe( | ||
null | ||
); | ||
expect(getHeaderToken({ headers: {} } as any)).toBe(null); | ||
expect( | ||
getHeaderToken({ headers: { authorization: 'Bearer xxx' } } as any) | ||
).toBe('xxx'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ export interface IConfig { | |
* Token expires in | ||
*/ | ||
expiresIn: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import { Boom, handleError } from "@ycs/error"; | ||
import { IContext } from "@ycs/interfaces"; | ||
import { Boom, handleError } from '@ycs/error'; | ||
import { IContext } from '@ycs/interfaces'; | ||
|
||
export function attachAuth() { | ||
return async (ctx: IContext, next) => { | ||
try { | ||
if (ctx.request.auth) { | ||
const auth = await this.model.findById(ctx.request.auth._id).exec(); | ||
if (!auth) | ||
throw Boom.notAcceptable( | ||
this.config.messages.errors.invalid_token | ||
); | ||
throw Boom.notAcceptable(this.config.messages.errors.invalid_token); | ||
} | ||
await next(); | ||
} catch (e) { | ||
handleError(ctx, e); | ||
} | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { Boom, handleError } from "@ycs/error"; | ||
import { IContext } from "@ycs/interfaces"; | ||
import { Boom, handleError } from '@ycs/error'; | ||
import { IContext } from '@ycs/interfaces'; | ||
|
||
export function hasRoles(...roles: string[]) { | ||
return async (ctx: IContext, next) => { | ||
try { | ||
for (const role of roles) { | ||
if (!ctx.request.auth.roles.includes(role)) | ||
throw Boom.forbidden( | ||
this.config.messages.errors.no_permission | ||
); | ||
throw Boom.forbidden(this.config.messages.errors.no_permission); | ||
} | ||
await next(); | ||
} catch (e) { | ||
handleError(ctx, e); | ||
} | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters