- yarn install
- yarn dev
Update to Server
- yarn build (we build in local)!!
- selfpaths - git pull origin master
- selfpaths - pm2 restart 3
How to update in digitalOcean server tutorial
- Go to Server
- sudo ufw allow 1337/tcp
- sudo ufw enable , y
- cd /var/www/eccxxx-backend
- pm2 start ecosystem.config.js
npx create-strapi-app project-name --quickstart yarn add strapi-plugin-magic
Frontend Bulit with
- Magic docs
- NextJs
In strapi admin dashboard
- magic (sidebar) - sercet key (copy from magic dashboard)
- it will added magic into strapi
extensions/user-permissions/config/policies/permissions.js
- added policies folder and file
- copy permission from github strapi link
- add below line in line 5
await strapi.plugins["magic"].services["magic"].loginWithMagic(ctx);
/api/order/controllers/order.js order controller, let user only retrieve their order record only.
{
"product": {"id": 1}
}
{
"method": "POST",
"path": "/orders/confirm",
"handler": "order.confirm",
"config": {
"policies": []
}
},
{
"checkout_session": "cs_test_a1DHvLVvRUl050e0NW0NDaKiORx0XwVgbqDQKmHaBxc4AtBTXq4Cr9tHfO"
}
strapi email: [email protected] strapi password: Password@123
How i started from:
- Install strapi for backend
- Create Product Collection (name will automatically plural)
- Create Product item
- Settings - Users && Permission plguin - identity - public (checked: find && findOne)
- Install NextJs for frontend
- Create utils urls(paste: Magic TEST key as default) and format
- Install magic-sdk (which helps authorization to frontend)
- Create useAuth Context
- Create checkUserLoggedIn function when refresh re-login again
- Yarn add strapi-plugin-magic (Making authenticated requests to Strapi)
- Kill server and restart
- Copy magic secret key to store in strapi Admin
- Added folder for permissions
- Added one line code in line 5 (check top details) (making authenticated request to strapi)
- Test Api with JWT token - http://localhost:1337/products
- After Test with Auth user, auth user will be added into User Collection.
- Create Order Collection
- Setting Relation, Product has many Orders
- Setting Relation, User has many Orders
- Testing doing manully add order, checkout_session: randomString, User(Select user), Product (Select Product)
- Settings - Users && Permission plguin - identity - authenticated (checked: find && findOne)
- Test Api with JWT token - http://localhost:1337/orders
- Get all orders event not belongs to the user
- Edit backend/api/order/controllers/orders.js (to let user only can retrieve what order belongs to him)
- Create useOrders custom hook in account.
- Fetch orders with authentication bearer token, which like Test Api in orders
- Listing Order item in account page.
- Seting loading state for orders
- Yarn add stripe in backend
- Enter stripe web - login - Developers - API keys - secret keys
- ADD secret key in backend .env
- Go To order Controller, require stripe and key and order create function, create function return id of sesiion ready use for frontend
- Settings - Users && Permission plguin - identity - authenticated (checked: create)
- Test Api with JWT Token - Body(JSON), - http://localhost:1337/orders
- Strapi Admin will added one order with unpaid
- yarn add @stripe/stripe-js (install frontend stripe sdk) in frontend
- Added TEST key from stripe in utils/url.
- Create component BuyButton, and integate with stripe sdk.
- Test Buy feature, It succefull and redirect back, but it still is unpaid in strapi order collection.
- Go to Backend controllers/order.js, add confirm function.
- Need to added this confirm into our routes
- backend/api/order/config/routes.json
- Go To Strapi Admin - Settings - identity - public (checked: order's confirm)
- Test Api with JWT Token - Body(JSON) - http://localhost:1337/orders/confirm
- Successful (success_url, order controller, hit confirm function) - Strapi Order unpaid updated to paid
- Yarn add strapi-provider-upload-aws-s3 in backend for upload image to cloud
- create ./config/plugins.js docs
- Go to aws s3 - create bucket
- Copy bucket name into plguins.js and region ap-southeast-1
- Uncheck Block all public access, then it able to file upload
- Click top bar name - security credentials - create access keys
- access key id and secret
- yarn add uuidv4 in backend for order tracking id