Skip to content

Commit b5fdee2

Browse files
committed
[Core] Improve security
1 parent a625a84 commit b5fdee2

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import '@fortawesome/fontawesome-free/css/all.css';
22
import 'vue-color/style.css';
33
import App from './App.vue';
44
import Notifications from '@kyvg/vue3-notification';
5+
import {
6+
backend
7+
} from './ts/util/url';
58
import {
69
createApp
710
} from 'vue';
@@ -21,14 +24,14 @@ app.use( Notifications );
2124

2225
if ( import.meta.env.VITE_BACKEND_URL ) {
2326
console.warn( 'Env var VITE_BACKEND_URL set: Backend at', import.meta.env.VITE_BACKEND_URL );
24-
localStorage.setItem( 'url', import.meta.env.VITE_BACKEND_URL );
27+
backend.url = import.meta.env.VITE_BACKEND_URL;
2528
} else if ( import.meta.env.MODE === 'production' || import.meta.env.VITE_OVERRIDE_PROD === 'true' ) {
2629
if ( import.meta.env.VITE_OVERRIDE_PROD === 'true' ) console.warn( 'Env var VITE_OVERRIDE_PROD set: using production backend' );
2730

28-
localStorage.setItem( 'url', 'https://api.' + location.host );
31+
backend.url = 'https://api.' + location.host;
2932
} else {
3033
console.warn( 'Running against local backend' );
31-
localStorage.setItem( 'url', 'http://localhost:8080' );
34+
backend.url = 'http://localhost:8080';
3235
}
3336

3437
if ( import.meta.env.VITE_DISABLE_LOGIN_CHECK || import.meta.env.VITE_DEV_MODE ) {

src/ts/auth/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type {
22
JWT
33
} from '@/types/jwt';
4+
import {
5+
backend
6+
} from '../util/url';
47
import magicLinks from './magic-links';
58
import {
69
ref
@@ -23,7 +26,7 @@ const login = async ( id: string, password: string ): Promise<void> => {
2326
const status = useStatusStore();
2427

2528
try {
26-
const res = await fetch( localStorage.getItem( 'url' ) + '/auth/login', {
29+
const res = await fetch( backend.url + '/auth/login', {
2730
'method': 'POST',
2831
'headers': {
2932
'Content-Type': 'application/json'
@@ -166,7 +169,7 @@ const logout = (): void => {
166169

167170
const signup = ( username: string, email: string, pw: string, type: 'SURVEY_ADMIN' | 'CROWD_SOURCE' ): Promise<boolean> => {
168171
return new Promise( ( resolve, reject ) => {
169-
fetch( localStorage.getItem( 'url' ) + '/auth/register', {
172+
fetch( backend.url + '/auth/register', {
170173
'method': 'POST',
171174
'headers': {
172175
'Content-Type': 'application/json'

src/ts/util/request.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import {
2+
backend
3+
} from './url';
14
import router from '@/ts/router';
25
import {
36
useNotification
@@ -104,7 +107,7 @@ const requestWithOpts = ( url: string, opts: RequestInit, noRedirect = false ):
104107
return Promise.reject( 'NO_AUTH' );
105108
}
106109

107-
const baseUrl = localStorage.getItem( 'url' );
110+
const baseUrl = backend.url;
108111

109112
if ( !baseUrl ) {
110113
return Promise.reject( 'NO_URL' );

src/ts/util/url.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const backend = {
2+
'url': 'https://api.eyetap.ivia.ch'
3+
};

0 commit comments

Comments
 (0)