Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project-melon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160381
project-melon
Commits
3d69bd48
Commit
3d69bd48
authored
1 month ago
by
65160381
Browse files
Options
Downloads
Patches
Plain Diff
9.5
parent
3970b8e3
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#621
passed with warnings
1 month ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.js
+9
-1
9 additions, 1 deletion
app.js
public/index.html
+14
-11
14 additions, 11 deletions
public/index.html
with
23 additions
and
12 deletions
app.js
+
9
−
1
View file @
3d69bd48
...
...
@@ -125,7 +125,15 @@ app.post('/login', async (req, res) => {
}
});
app
.
get
(
'
/api/getUser
'
,
(
req
,
res
)
=>
{
if
(
req
.
session
.
user
)
{
res
.
json
({
email
:
req
.
session
.
user
.
email
// ส่งข้อมูล email จาก session
});
}
else
{
res
.
status
(
401
).
send
(
'
User not logged in
'
);
}
});
// Fetch products of logged-in user
app
.
get
(
'
/api/user/products
'
,
(
req
,
res
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
public/index.html
+
14
−
11
View file @
3d69bd48
...
...
@@ -107,19 +107,22 @@
// Display user's email from session
async
function
displayUsername
()
{
try
{
const
response
=
await
fetch
(
'
/api/getUser
'
);
// Endpoint to get the user's email
if
(
response
.
status
===
401
)
{
console
.
log
(
'
User not logged in
'
);
document
.
getElementById
(
'
welcome-message
'
).
innerText
=
'
Please log in
'
;
}
else
{
const
user
=
await
response
.
json
();
document
.
getElementById
(
'
welcome-message
'
).
innerText
=
`Welcome,
${
user
.
email
}
`
;
// Display email here
}
}
catch
(
error
)
{
console
.
log
(
'
Error fetching user info:
'
,
error
);
try
{
const
response
=
await
fetch
(
'
/api/getUser
'
);
// Endpoint to get the user's email
if
(
response
.
status
===
401
)
{
console
.
log
(
'
User not logged in
'
);
document
.
getElementById
(
'
welcome-message
'
).
innerText
=
'
Please log in
'
;
}
else
{
const
user
=
await
response
.
json
();
document
.
getElementById
(
'
welcome-message
'
).
innerText
=
`Welcome,
${
user
.
email
}
`
;
// Display email here
}
}
catch
(
error
)
{
console
.
log
(
'
Error fetching user info:
'
,
error
);
}
}
// เรียกใช้ฟังก์ชันเมื่อหน้าเว็บโหลดเสร็จ
window
.
onload
=
displayUsername
;
// Initially load products, cart item count, and user info
fetchProducts
();
// Fetch all products initially
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment