Comments (11)
So it doesn't matter if the inserted ULID is the primary key. Anyway, is multitenancy the correct way to do this or is there a better way? (aside from client-side ID generation) π
I also tried using customization.beforeHandler and it got the same result
from php-crud-api.
So i got it to return the new ULID by adding it in the afterHandler.
'customization.beforeHandler' => function ($operation, $tableName, $request, $environment) {
if($operation =='create' && $tableName =='data'){
$body = $request->getParsedBody();
$body->id = $environment->ulid = Ulid::generate();
return $request->withParsedBody($body);
}
},
'customization.afterHandler' => function ($operation, $tableName, $response, $environment) {
if($operation =='create' && $tableName =='data'){
return ResponseFactory::from(200, 'text/plain',$environment->ulid);
}
},
It's not very good-looking code but it kinda works for my use case. (Although I'm not sure if this is a correct way to use the $environment variable.)π
from php-crud-api.
Excellent, that is exactly how that I envisioned that it would be used! Keep it up..
from php-crud-api.
depends on the order of the middlewares.
But it seems that no matter how I order the middlewares, the ULID is not inserted via the customization beforeHandler during dbAuth registration request.
from php-crud-api.
Yup,that's the case.But it may not be a very common use case as of now. For now, I'll just copy some code in the register endpoint and insert it in my beforeHandler as a temp. workaroundπ
For future, this feature might good to be implemented in an enhanced dbAuth middleware that can accept extra registration data.
from php-crud-api.
With SQLite, the post request is ok (data is saved and response status is HTTP 200) but returns {} or an empty array. Any idea why?
I think it is because the code returns the insert(ed) id and not the primary key.
from php-crud-api.
Just noting here that the before/afterHandler does not work with user registration even though it's a POST request.
from php-crud-api.
@apps-caraga I would say that depends on the order of the middlewares.
from php-crud-api.
Did you load the Customization handler before DbAuth? You test for 'create' operation, while the DbAuth uses the 'unknown' if I read the code correctly. Did you debug the code? You should be able to do something when calling Customization before DbAuth.
from php-crud-api.
You should be able to do something when calling Customization before DbAuth.
I was able to retrieve the path segment thru RequestUtils::getPathSegment($request, 1)
; parameters so I can check if the current path or operation is 'login','register', or 'logout' operation instead of just checking if the operation is 'unknown'. Then I was able to add the new ID to the $body.
'customization.beforeHandler' => function ($operation, $tableName, $request, $environment) {
$body = $request->getParsedBody();
$path = RequestUtils::getPathSegment($request, 1);
if($path === 'register' ){
$body->id = $environment->ulid = Ulid::generate()->__toString();
$environment->currPath = $path;
return $request->withParsedBody($body);
}
},
The problem is the dbAuth register processes only the $username
and $password
so the custom ID added to the body is ignored (line 60-61 of DbAuth middleware ) π
from php-crud-api.
I think it cannot be done without modifying the dbAuth middleware
from php-crud-api.
Related Issues (20)
- HTML Middleware HOT 2
- Update with "where" HOT 8
- "Request Tranformer" middleware HOT 2
- Azure App Service HOT 1
- Add PHP backend to any app project with one command HOT 1
- Any advice on events integration? HOT 2
- Synchronization between local IndexedDB and MySQL Database. HOT 3
- Can the API Support Customized Cache Management for Specific Tables? HOT 9
- Question: Add property on create HOT 3
- Insights on caching with Redis HOT 2
- PUT using curl comes back successful but the record is not actually updated HOT 2
- Suggestion to modify response JSON root Key (records) HOT 2
- firebase jwt public key rotation HOT 5
- "Route '' not found" HOT 3
- Additional SQL queries in authorization handlers HOT 2
- Direct usage of PHP CRUD API functions in external PHP Files HOT 8
- Failure on postgres when table name is domains HOT 10
- Returning user uploaded file using custom controller HOT 2
- Found this PDOException occurred (enable debug mode) in message HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-crud-api.