feat: create login request api (in comments)
This commit is contained in:
parent
f0c12defa1
commit
91ce87d06f
@ -2,20 +2,17 @@ import { ref, computed } from 'vue'
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { dispatchNotification } from '@/components/Notification'
|
import { dispatchNotification } from '@/components/Notification'
|
||||||
import { readData, removeData, writeData, writeDataJson } from '@/utils/storage'
|
import { readData, removeData, writeData, writeDataJson } from '@/utils/storage'
|
||||||
import router from '@/router'
|
import { authenticateUser } from '@/utils/api/api.rest'
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
// token from localStorage
|
|
||||||
const token = ref(readData('token') || '')
|
const token = ref(readData('token') || '')
|
||||||
// create a shared state
|
|
||||||
const username = ref('')
|
const username = ref('')
|
||||||
const password = ref('')
|
const password = ref('')
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const isLoggedIn = computed(() => token.value !== '')
|
const isLoggedIn = computed(() => token.value !== '')
|
||||||
const filterPresets: any = ref({})
|
const filterPresets: any = ref({})
|
||||||
|
|
||||||
// define your actions
|
const login = async () => {
|
||||||
const login = () => {
|
|
||||||
if (username.value == '' || password.value == '') {
|
if (username.value == '' || password.value == '') {
|
||||||
dispatchNotification({
|
dispatchNotification({
|
||||||
title: 'Perhatian',
|
title: 'Perhatian',
|
||||||
@ -23,7 +20,16 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
type: 'warning'
|
type: 'warning'
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
// isLoading.value = true
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const response = await authenticateUser(username.value, password.value)
|
||||||
|
|
||||||
|
// if (response.success) {
|
||||||
|
// writeData('token', response.token)
|
||||||
|
|
||||||
// filterPresets.value = {
|
// filterPresets.value = {
|
||||||
|
// regional
|
||||||
// uid: {
|
// uid: {
|
||||||
// id: 2,
|
// id: 2,
|
||||||
// name: 'DISTRIBUSI JAKARTA RAYA'
|
// name: 'DISTRIBUSI JAKARTA RAYA'
|
||||||
@ -35,7 +41,36 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
// posko: {
|
// posko: {
|
||||||
// id: 541101,
|
// id: 541101,
|
||||||
// name: 'POSKO MENTENG'
|
// name: 'POSKO MENTENG'
|
||||||
|
// },
|
||||||
|
// ulp,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// if (Object.keys(filterPresets.value).length > 0) {
|
||||||
|
// writeDataJson('filterPresets', filterPresets.value)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// dispatchNotification({
|
||||||
|
// title: 'Berhasil',
|
||||||
|
// content: 'Login berhasil, selamat datang kembali!',
|
||||||
|
// type: 'success'
|
||||||
|
// })
|
||||||
|
|
||||||
|
// window.location.reload()
|
||||||
|
// } else {
|
||||||
|
// dispatchNotification({
|
||||||
|
// title: 'Login Gagal',
|
||||||
|
// content: 'Username atau password salah',
|
||||||
|
// type: 'error'
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// dispatchNotification({
|
||||||
|
// title: 'Login Gagal',
|
||||||
|
// content: 'Terjadi kesalahan saat melakukan login',
|
||||||
|
// type: 'error'
|
||||||
|
// })
|
||||||
|
// } finally {
|
||||||
|
// isLoading.value = false
|
||||||
// }
|
// }
|
||||||
|
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
|
@ -18,6 +18,16 @@ const getUp3 = async (uid: number) => await instance.get('/up3?uid=' + uid)
|
|||||||
const getUlp = async (up3: number) => await instance.get('/ulp?up3=' + up3)
|
const getUlp = async (up3: number) => await instance.get('/ulp?up3=' + up3)
|
||||||
const getPosko = async (uppp: number) => await instance.get('/posko?up3=' + uppp)
|
const getPosko = async (uppp: number) => await instance.get('/posko?up3=' + uppp)
|
||||||
const getVersion = async () => await ax.get('/version.json')
|
const getVersion = async () => await ax.get('/version.json')
|
||||||
|
|
||||||
|
const authenticateUser = async (username: string, password: string) => {
|
||||||
|
const res = await instance.post('/auth', {
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
})
|
||||||
|
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getUid,
|
getUid,
|
||||||
getUp3,
|
getUp3,
|
||||||
@ -27,5 +37,6 @@ export {
|
|||||||
getJenisTransaksi,
|
getJenisTransaksi,
|
||||||
getUidRegional,
|
getUidRegional,
|
||||||
getRegional,
|
getRegional,
|
||||||
getVersion
|
getVersion,
|
||||||
|
authenticateUser
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user