feat: add GitHub OAuth2 login and protect product mutations with JWT
- add /auth/login and /auth/callback (rewritten to pages/api/auth/*) for the GitHub Authorization Code flow, with a state cookie against login CSRF - issue a 1h JWT after the code exchange and verify it (HS256) in the Apollo context; createProduct, updateProduct and deleteProduct require it - set products.created_by from the logged-in GitHub user (upsert into users) - preset the Authorization header in the embedded Sandbox - add jsonwebtoken, drop unused cors, rename package to week-7
This commit is contained in:
+3
-1
@@ -15,6 +15,8 @@ function Home() {
|
||||
target: '#embedded-sandbox',
|
||||
initialEndpoint: `${window.location.origin}/api/graphql`,
|
||||
initialState: {
|
||||
// Ganti <paste-token-here> dengan JWT dari /auth/login supaya mutation diizinkan.
|
||||
headers: { Authorization: 'Bearer <paste-token-here>' },
|
||||
document: `query TestCategoriesWithProducts {
|
||||
categories {
|
||||
id
|
||||
@@ -44,7 +46,7 @@ function Home() {
|
||||
React.createElement(
|
||||
Head,
|
||||
null,
|
||||
React.createElement('title', null, 'GraphQL Sandbox - Lab 04')
|
||||
React.createElement('title', null, 'GraphQL Sandbox')
|
||||
),
|
||||
React.createElement('div', {
|
||||
id: 'embedded-sandbox',
|
||||
|
||||
Reference in New Issue
Block a user