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 { dispatchNotification } from '@/components/Notification'
|
||||
import { readData, removeData, writeData, writeDataJson } from '@/utils/storage'
|
||||
import router from '@/router'
|
||||
import { authenticateUser } from '@/utils/api/api.rest'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
// token from localStorage
|
||||
const token = ref(readData('token') || '')
|
||||
// create a shared state
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const isLoading = ref(false)
|
||||
const isLoggedIn = computed(() => token.value !== '')
|
||||
const filterPresets: any = ref({})
|
||||
|
||||
// define your actions
|
||||
const login = () => {
|
||||
const login = async () => {
|
||||
if (username.value == '' || password.value == '') {
|
||||
dispatchNotification({
|
||||
title: 'Perhatian',
|
||||
@ -23,7 +20,16 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
type: 'warning'
|
||||
})
|
||||
} else {
|
||||
// isLoading.value = true
|
||||
|
||||
// try {
|
||||
// const response = await authenticateUser(username.value, password.value)
|
||||
|
||||
// if (response.success) {
|
||||
// writeData('token', response.token)
|
||||
|
||||
// filterPresets.value = {
|
||||
// regional
|
||||
// uid: {
|
||||
// id: 2,
|
||||
// name: 'DISTRIBUSI JAKARTA RAYA'
|
||||
@ -35,7 +41,36 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
// posko: {
|
||||
// id: 541101,
|
||||
// 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
|
||||
|
@ -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 getPosko = async (uppp: number) => await instance.get('/posko?up3=' + uppp)
|
||||
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 {
|
||||
getUid,
|
||||
getUp3,
|
||||
@ -27,5 +37,6 @@ export {
|
||||
getJenisTransaksi,
|
||||
getUidRegional,
|
||||
getRegional,
|
||||
getVersion
|
||||
getVersion,
|
||||
authenticateUser
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user