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