Update the format

This commit is contained in:
jetli 2024-09-09 16:18:11 -07:00
parent 0628ad507f
commit 1abbb121c0
3 changed files with 18 additions and 14 deletions

View File

@ -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')

View File

@ -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) {

View File

@ -1,5 +1,5 @@
import axios from 'axios'
import { jwtDecode } from 'jwt-decode';
import { jwtDecode } from 'jwt-decode'
const backendAxios = axios.create({
baseURL: '',
@ -34,8 +34,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 +44,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