Merge branch 'main' into dev0909
This commit is contained in:
commit
878da11d40
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,4 +13,5 @@ ythe.sh
|
||||
/logs/
|
||||
*build*
|
||||
package-lock.json
|
||||
.vite
|
||||
.vite
|
||||
.idea
|
||||
|
||||
@ -57,8 +57,8 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
trySigninWithEmail() {
|
||||
// Prevent the page from refreshing on form submission
|
||||
event.preventDefault();
|
||||
// Prevent the page from refreshing on form submission
|
||||
event.preventDefault()
|
||||
this.message = null
|
||||
if (this.email === null || this.email.length < 1) {
|
||||
this.message = this.$t('Please type in your email')
|
||||
|
||||
@ -79,12 +79,12 @@ export default {
|
||||
UserAuthApi.signinByEmail(this.email, this.password)
|
||||
.then((response) => {
|
||||
// Extract the necessary data from the response
|
||||
const { access_token, refresh_token, expires_in } = response.data;
|
||||
const { access_token, refresh_token, expires_in } = response.data
|
||||
|
||||
// Save tokens and expiration time in localStorage
|
||||
localStorage.setItem('access_token', access_token);
|
||||
localStorage.setItem('refresh_token', refresh_token);
|
||||
localStorage.setItem('expires_in', expires_in);
|
||||
localStorage.setItem('access_token', access_token)
|
||||
localStorage.setItem('refresh_token', refresh_token)
|
||||
localStorage.setItem('expires_in', expires_in)
|
||||
|
||||
let signinAction = response.data.signin_result
|
||||
switch (signinAction) {
|
||||
|
||||
@ -1,11 +1,8 @@
|
||||
import axios from 'axios'
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
import { jwtDecode } from 'jwt-decode'
|
||||
|
||||
const backendAxios = axios.create({
|
||||
baseURL: '',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
baseURL: ''
|
||||
})
|
||||
|
||||
// Function to check if the token has expired
|
||||
@ -34,8 +31,8 @@ backendAxios.interceptors.request.use(
|
||||
let accessToken = localStorage.getItem('access_token')
|
||||
let refreshToken = localStorage.getItem('refresh_token')
|
||||
// Fix: handle the case where localStorage returns 'null' as a string
|
||||
if (accessToken === 'null') accessToken = null;
|
||||
if (refreshToken === 'null') refreshToken = null;
|
||||
if (accessToken === 'null') accessToken = null
|
||||
if (refreshToken === 'null') refreshToken = null
|
||||
|
||||
// Check if the access token is expired
|
||||
if (accessToken == null || refreshToken == null) {
|
||||
@ -44,12 +41,16 @@ backendAxios.interceptors.request.use(
|
||||
if (isTokenExpired(accessToken)) {
|
||||
try {
|
||||
// If access token is expired, refresh it using the refresh token
|
||||
const response = await axios.post('/api/user/signin/refresh-token', {}, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${refreshToken}`,
|
||||
'Content-Type': 'application/json'
|
||||
const response = await axios.post(
|
||||
'/api/user/signin/refresh-token',
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${refreshToken}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
});
|
||||
)
|
||||
accessToken = response.data.access_token
|
||||
refreshToken = response.data.refresh_token
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user