-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ts custom auth #609
ts custom auth #609
Conversation
node.js/authentication.md
Outdated
The TypeScript equivalent has to use the default export. | ||
|
||
```ts | ||
export default function custom_auth(req: any, res: any, next: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use proper types:
import { Request } from '@sap/cds';
export default function custom_auth(request: Request, response: Response, next: Function) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The request
here is the express request object. There might be types available for express as well but I'd prefer to have that snippet as simple as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Express request doesn't have "user" property which you might want to set here. That's why I import cds type. Response can be imported from express types.
Proper typing is important for ts example. With all those anys you might as well convert it to js example. "export default" is perfectly valid in js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cds.Request
type is simply wrong as e. g. query
has a completely different semantic in the express request object.
For proper type support one would need to enhance the request type of express. I'll double check for improving the snippet. If it grows too big, I'll add a comment in the snippet.
will be develivered with cds 7.6