forked from noxious/client
#190 : Cookie domain improvement
This commit is contained in:
parent
7c259f455c
commit
08f55c9680
@ -1,6 +1,7 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
import { useCookies } from '@vueuse/integrations/useCookies'
|
import { useCookies } from '@vueuse/integrations/useCookies'
|
||||||
|
import { getDomain } from '@/utilities'
|
||||||
|
|
||||||
export async function register(username: string, email: string, password: string) {
|
export async function register(username: string, email: string, password: string) {
|
||||||
try {
|
try {
|
||||||
@ -16,9 +17,7 @@ export async function login(username: string, password: string) {
|
|||||||
try {
|
try {
|
||||||
const response = await axios.post(`${config.server_endpoint}/login`, { username, password })
|
const response = await axios.post(`${config.server_endpoint}/login`, { username, password })
|
||||||
useCookies().set('token', response.data.token as string, {
|
useCookies().set('token', response.data.token as string, {
|
||||||
// for whole domain
|
domain: getDomain()
|
||||||
// @TODO : #190
|
|
||||||
// domain: window.location.hostname.split('.').slice(-2).join('.')
|
|
||||||
})
|
})
|
||||||
return { success: true, token: response.data.token }
|
return { success: true, token: response.data.token }
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
@ -105,9 +105,7 @@ export const useGameStore = defineStore('game', {
|
|||||||
this.connection?.disconnect()
|
this.connection?.disconnect()
|
||||||
|
|
||||||
useCookies().remove('token', {
|
useCookies().remove('token', {
|
||||||
// for whole domain
|
domain: getDomain()
|
||||||
// @TODO : #190
|
|
||||||
// domain: window.location.hostname.split('.').slice(-2).join('.')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
this.isAssetsLoaded = false
|
this.isAssetsLoaded = false
|
||||||
|
@ -5,3 +5,21 @@ export function uuidv4() {
|
|||||||
export function unduplicateArray(array: any[]) {
|
export function unduplicateArray(array: any[]) {
|
||||||
return [...new Set(array.flat())]
|
return [...new Set(array.flat())]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getDomain() {
|
||||||
|
// Check if not localhost
|
||||||
|
if (window.location.hostname !== 'localhost') {
|
||||||
|
return window.location.hostname
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if not IP address
|
||||||
|
if (window.location.hostname.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) {
|
||||||
|
return window.location.hostname
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.location.hostname.split('.').length < 3) {
|
||||||
|
return window.location.hostname
|
||||||
|
}
|
||||||
|
|
||||||
|
return window.location.hostname.split('.').slice(-2).join('.')
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user