feat: update
This commit is contained in:
@@ -29,6 +29,11 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
|
|||||||
return ctx.Next()
|
return ctx.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check is XMLHttpRequest
|
||||||
|
if ctx.XHR() {
|
||||||
|
return ctx.SendStatus(fiber.StatusUnauthorized)
|
||||||
|
}
|
||||||
|
|
||||||
fullUrl := utils.FullURI(ctx)
|
fullUrl := utils.FullURI(ctx)
|
||||||
u, err := url.Parse(fullUrl)
|
u, err := url.Parse(fullUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import axios from 'axios';
|
|||||||
const client = axios.create({
|
const client = axios.create({
|
||||||
baseURL: '/v1',
|
baseURL: '/v1',
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
|
withCredentials: true,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}
|
}
|
||||||
@@ -27,6 +28,12 @@ client.interceptors.response.use(
|
|||||||
error => {
|
error => {
|
||||||
// Handle HTTP errors here
|
// Handle HTTP errors here
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
|
// Handle 401 Unauthorized error
|
||||||
|
if (error.response.status === 401) {
|
||||||
|
const redirectUrl = encodeURIComponent(window.location.href);
|
||||||
|
window.location.href = `/v1/auth/wechat?redirect=${redirectUrl}`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Server responded with error status
|
// Server responded with error status
|
||||||
console.error('API Error:', error.response.status, error.response.data);
|
console.error('API Error:', error.response.status, error.response.data);
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user