Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finwise-miniapp-be
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ThinhNC
finwise-miniapp-be
Commits
93ab2d01
Commit
93ab2d01
authored
Sep 11, 2026
by
ThinhNC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: implement authentication service with JWT handling, device tracking, and email verification
parent
236dc091
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
11 deletions
+20
-11
auth.service.ts
src/modules/auth/auth.service.ts
+20
-11
No files found.
src/modules/auth/auth.service.ts
View file @
93ab2d01
...
...
@@ -459,6 +459,9 @@ export class AuthService {
):
Promise
<
LoginResponseDto
>
{
const
{
accessToken
}
=
dto
;
const
appSecret
=
process
.
env
.
ZALO_APP_SECRET
||
''
;
const
appsecretProof
=
appSecret
?
crypto
.
createHmac
(
'sha256'
,
appSecret
).
update
(
accessToken
).
digest
(
'hex'
)
:
''
;
// 1. Xác thực access_token và lấy thông tin Zalo profile (có fallback khi IP server ở nước ngoài)
let
zaloId
=
dto
.
zaloId
||
''
;
...
...
@@ -474,11 +477,6 @@ export class AuthService {
});
try
{
const
appsecretProof
=
crypto
.
createHmac
(
'sha256'
,
appSecret
)
.
update
(
accessToken
)
.
digest
(
'hex'
);
const
zaloProfile
=
await
this
.
fetchZaloProfile
(
accessToken
,
appsecretProof
);
console
.
log
(
'[ZaloAuth] fetchZaloProfile response:'
,
zaloProfile
);
if
(
zaloProfile
&&
zaloProfile
.
id
)
{
...
...
@@ -505,7 +503,7 @@ export class AuthService {
if
(
dto
.
phoneToken
)
{
try
{
const
phoneResponse
=
await
this
.
fetchZaloPhoneNumber
(
accessToken
,
dto
.
phoneToken
,
appSecret
);
const
phoneResponse
=
await
this
.
fetchZaloPhoneNumber
(
accessToken
,
dto
.
phoneToken
,
appSecret
,
appsecretProof
);
console
.
log
(
'[ZaloAuth] fetchZaloPhoneNumber response:'
,
phoneResponse
);
if
(
phoneResponse
&&
phoneResponse
.
data
?.
number
)
{
resolvedPhone
=
phoneResponse
.
data
.
number
;
...
...
@@ -694,17 +692,28 @@ export class AuthService {
accessToken
:
string
,
phoneToken
:
string
,
appSecret
:
string
,
appsecretProof
?:
string
,
):
Promise
<
ZaloPhoneResponse
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
proof
=
appsecretProof
||
(
appSecret
?
crypto
.
createHmac
(
'sha256'
,
appSecret
).
update
(
accessToken
).
digest
(
'hex'
)
:
''
);
const
headers
:
Record
<
string
,
string
>
=
{
access_token
:
accessToken
,
code
:
phoneToken
,
secret_key
:
appSecret
,
};
if
(
proof
)
{
headers
.
appsecret_proof
=
proof
;
}
const
options
=
{
hostname
:
'graph.zalo.me'
,
path
:
'/v2.0/me/info'
,
method
:
'GET'
,
headers
:
{
access_token
:
accessToken
,
code
:
phoneToken
,
secret_key
:
appSecret
,
},
headers
,
};
const
req
=
https
.
request
(
options
,
(
res
)
=>
{
let
data
=
''
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment