Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finwise-miniapp-fe
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-fe
Commits
e693bcf4
You need to sign in or sign up before continuing.
Commit
e693bcf4
authored
Aug 29, 2026
by
ThinhNC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(auth): streamline login with Zalo SDK and Claymorphism UI
parent
29c7ecf9
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
199 additions
and
175 deletions
+199
-175
use-zalo-login.ts
src/hooks/use-zalo-login.ts
+72
-0
en.json
src/i18n/locales/en.json
+15
-1
vi.json
src/i18n/locales/vi.json
+15
-1
login.tsx
src/pages/auth/login.tsx
+89
-173
auth.service.ts
src/services/auth.service.ts
+8
-0
No files found.
src/hooks/use-zalo-login.ts
0 → 100644
View file @
e693bcf4
import
{
useState
}
from
"react"
;
import
{
getAccessToken
,
getPhoneNumber
}
from
"zmp-sdk"
;
import
{
useNavigate
,
useSnackbar
}
from
"zmp-ui"
;
import
{
authService
}
from
"@/services/auth.service"
;
import
{
useAuthStore
}
from
"@/stores/auth-store"
;
import
{
getErrorMessage
}
from
"@/lib/error-message"
;
import
{
useI18n
}
from
"@/i18n"
;
interface
UseZaloLoginReturn
{
handleZaloLogin
:
()
=>
Promise
<
void
>
;
isLoading
:
boolean
;
}
export
function
useZaloLogin
():
UseZaloLoginReturn
{
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
);
const
navigate
=
useNavigate
();
const
{
openSnackbar
}
=
useSnackbar
();
const
setAuth
=
useAuthStore
((
state
)
=>
state
.
setAuth
);
const
{
t
}
=
useI18n
();
const
handleZaloLogin
=
async
()
=>
{
setIsLoading
(
true
);
try
{
// 1. Lấy Zalo access token (string trực tiếp)
const
accessToken
=
await
getAccessToken
();
if
(
!
accessToken
)
{
throw
new
Error
(
t
(
"auth.zalo.tokenFailed"
));
}
// 2. Lấy số điện thoại từ Zalo SDK
// `number` là field deprecated nhưng trả về SĐT thực trên Mini App
// `token` là flow mới: cần gửi lên server Zalo để đổi lấy SĐT
const
phoneResult
=
await
getPhoneNumber
();
const
phoneNumber
=
phoneResult
.
number
;
if
(
!
phoneNumber
)
{
openSnackbar
({
type
:
"warning"
,
text
:
t
(
"auth.zalo.phoneDenied"
),
});
return
;
}
// 3. Gửi lên backend để xác thực + đăng nhập/tạo tài khoản
const
response
=
await
authService
.
loginWithZalo
({
accessToken
,
phoneNumber
});
if
(
response
.
success
&&
response
.
data
)
{
setAuth
(
response
.
data
.
user
,
response
.
data
.
accessToken
||
""
,
response
.
data
.
refreshToken
||
""
);
openSnackbar
({
type
:
"success"
,
text
:
t
(
"auth.zalo.loginSuccess"
),
});
navigate
(
"/"
,
{
replace
:
true
});
}
else
{
throw
new
Error
(
t
(
"auth.zalo.loginFailed"
));
}
}
catch
(
error
:
unknown
)
{
openSnackbar
({
type
:
"error"
,
text
:
getErrorMessage
(
error
,
t
(
"auth.zalo.loginFailed"
)),
});
}
finally
{
setIsLoading
(
false
);
}
};
return
{
handleZaloLogin
,
isLoading
};
}
src/i18n/locales/en.json
View file @
e693bcf4
...
@@ -160,7 +160,21 @@
...
@@ -160,7 +160,21 @@
"registerNow"
:
"Sign up now"
,
"registerNow"
:
"Sign up now"
,
"success"
:
"Signed in successfully!"
,
"success"
:
"Signed in successfully!"
,
"failed"
:
"Sign-in failed"
,
"failed"
:
"Sign-in failed"
,
"failedDetail"
:
"Sign-in failed. Please check your details and try again."
"failedDetail"
:
"Sign-in failed. Please check your details and try again."
,
"feature"
:
{
"wallet"
:
"Manage Wallets"
,
"report"
:
"Reports"
,
"ai"
:
"AI Assistant"
}
},
"zalo"
:
{
"loginButton"
:
"Sign in with Zalo"
,
"loggingIn"
:
"Signing in..."
,
"loginSuccess"
:
"Signed in successfully!"
,
"loginFailed"
:
"Sign-in failed, please try again."
,
"tokenFailed"
:
"Could not retrieve Zalo info, please try again."
,
"phoneDenied"
:
"Phone number permission is required to sign in."
,
"termsNote"
:
"By signing in, you agree to FinWise's terms of service."
},
},
"register"
:
{
"register"
:
{
"header"
:
"Sign Up"
,
"header"
:
"Sign Up"
,
...
...
src/i18n/locales/vi.json
View file @
e693bcf4
...
@@ -160,7 +160,21 @@
...
@@ -160,7 +160,21 @@
"registerNow"
:
"Đăng ký ngay"
,
"registerNow"
:
"Đăng ký ngay"
,
"success"
:
"Đăng nhập thành công! 🎉"
,
"success"
:
"Đăng nhập thành công! 🎉"
,
"failed"
:
"Đăng nhập thất bại"
,
"failed"
:
"Đăng nhập thất bại"
,
"failedDetail"
:
"Đăng nhập thất bại, vui lòng kiểm tra lại thông tin."
"failedDetail"
:
"Đăng nhập thất bại, vui lòng kiểm tra lại thông tin."
,
"feature"
:
{
"wallet"
:
"Quản lý ví"
,
"report"
:
"Báo cáo"
,
"ai"
:
"Trợ lý AI"
}
},
"zalo"
:
{
"loginButton"
:
"Đăng nhập bằng Zalo"
,
"loggingIn"
:
"Đang đăng nhập..."
,
"loginSuccess"
:
"Đăng nhập thành công!"
,
"loginFailed"
:
"Đăng nhập thất bại, vui lòng thử lại."
,
"tokenFailed"
:
"Không thể lấy thông tin Zalo, vui lòng thử lại."
,
"phoneDenied"
:
"Bạn cần cấp quyền số điện thoại để đăng nhập."
,
"termsNote"
:
"Bằng cách đăng nhập, bạn đồng ý với điều khoản sử dụng của FinWise."
},
},
"register"
:
{
"register"
:
{
"header"
:
"Đăng Ký"
,
"header"
:
"Đăng Ký"
,
...
...
src/pages/auth/login.tsx
View file @
e693bcf4
This diff is collapsed.
Click to expand it.
src/services/auth.service.ts
View file @
e693bcf4
...
@@ -71,4 +71,12 @@ export const authService = {
...
@@ -71,4 +71,12 @@ export const authService = {
const
response
=
await
apiClient
.
delete
(
"/auth/sessions"
);
const
response
=
await
apiClient
.
delete
(
"/auth/sessions"
);
return
response
.
data
;
return
response
.
data
;
},
},
async
loginWithZalo
(
data
:
{
accessToken
:
string
;
phoneNumber
:
string
;
}):
Promise
<
ApiResponse
<
{
user
:
User
;
accessToken
?:
string
;
refreshToken
?:
string
}
>>
{
const
response
=
await
apiClient
.
post
(
"/auth/zalo-login"
,
data
);
return
response
.
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