diff --git a/.eslintcache b/.eslintcache new file mode 100644 index 0000000..d40f987 --- /dev/null +++ b/.eslintcache @@ -0,0 +1 @@ +[{"/root/github/claptrap-ui/.eslintrc.cjs":"1","/root/github/claptrap-ui/env.d.ts":"2","/root/github/claptrap-ui/src/components/HeaderComponent.vue":"3","/root/github/claptrap-ui/src/main.ts":"4","/root/github/claptrap-ui/src/plugins/webfontloader.ts":"5","/root/github/claptrap-ui/src/router/index.ts":"6","/root/github/claptrap-ui/src/shims-vuetify.d.ts":"7","/root/github/claptrap-ui/src/stores/coockiesStorage.ts":"8","/root/github/claptrap-ui/src/stores/user.ts":"9","/root/github/claptrap-ui/src/views/HomeView.vue":"10","/root/github/claptrap-ui/src/views/oauth/OauthCallbackView.vue":"11","/root/github/claptrap-ui/src/views/oauth/OauthRedirectView.vue":"12","/root/github/claptrap-ui/vite.config.ts":"13"},{"size":334,"mtime":1653426082929,"results":"14","hashOfConfig":"15"},{"size":281,"mtime":1653426082929,"results":"16","hashOfConfig":"15"},{"size":1671,"mtime":1653426082929,"results":"17","hashOfConfig":"15"},{"size":441,"mtime":1653426082929,"results":"18","hashOfConfig":"15"},{"size":370,"mtime":1653426082929,"results":"19","hashOfConfig":"15"},{"size":1191,"mtime":1653426082929,"results":"20","hashOfConfig":"15"},{"size":108,"mtime":1653426082929,"results":"21","hashOfConfig":"15"},{"size":386,"mtime":1653426082929,"results":"22","hashOfConfig":"15"},{"size":1795,"mtime":1653426152150,"results":"23","hashOfConfig":"15"},{"size":421,"mtime":1653426082929,"results":"24","hashOfConfig":"15"},{"size":668,"mtime":1653426082929,"results":"25","hashOfConfig":"15"},{"size":436,"mtime":1653426082929,"results":"26","hashOfConfig":"15"},{"size":713,"mtime":1653426220387,"results":"27","hashOfConfig":"15"},{"filePath":"28","messages":"29","suppressedMessages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"ekl415",{"filePath":"31","messages":"32","suppressedMessages":"33","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","suppressedMessages":"36","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"37","messages":"38","suppressedMessages":"39","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","suppressedMessages":"42","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"43","messages":"44","suppressedMessages":"45","errorCount":0,"fatalErrorCount":0,"warningCount":2,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"46","messages":"47","suppressedMessages":"48","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"49","messages":"50","suppressedMessages":"51","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"52","messages":"53","suppressedMessages":"54","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"55","messages":"56","suppressedMessages":"57","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","suppressedMessages":"60","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"61","messages":"62","suppressedMessages":"63","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"64","messages":"65","suppressedMessages":"66","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/root/github/claptrap-ui/.eslintrc.cjs",[],[],"/root/github/claptrap-ui/env.d.ts",[],[],"/root/github/claptrap-ui/src/components/HeaderComponent.vue",[],[],"/root/github/claptrap-ui/src/main.ts",[],[],"/root/github/claptrap-ui/src/plugins/webfontloader.ts",[],[],"/root/github/claptrap-ui/src/router/index.ts",["67","68"],[],"/root/github/claptrap-ui/src/shims-vuetify.d.ts",[],[],"/root/github/claptrap-ui/src/stores/coockiesStorage.ts",["69"],[],"/root/github/claptrap-ui/src/stores/user.ts",["70"],[],"/root/github/claptrap-ui/src/views/HomeView.vue",[],[],"/root/github/claptrap-ui/src/views/oauth/OauthCallbackView.vue",[],[],"/root/github/claptrap-ui/src/views/oauth/OauthRedirectView.vue",["71"],[],"/root/github/claptrap-ui/vite.config.ts",[],[],{"ruleId":"72","severity":1,"message":"73","line":43,"column":24,"nodeType":"74","messageId":"75","endLine":43,"endColumn":28},{"ruleId":"76","severity":1,"message":"77","line":46,"column":7,"nodeType":"78","messageId":"79","endLine":46,"endColumn":10,"suggestions":"80"},{"ruleId":"72","severity":1,"message":"81","line":8,"column":7,"nodeType":"74","messageId":"75","endLine":8,"endColumn":12},{"ruleId":"72","severity":1,"message":"82","line":30,"column":13,"nodeType":"74","messageId":"75","endLine":30,"endColumn":18},{"ruleId":"72","severity":1,"message":"83","line":15,"column":7,"nodeType":"74","messageId":"75","endLine":15,"endColumn":11},"@typescript-eslint/no-unused-vars","'from' is defined but never used.","Identifier","unusedVar","@typescript-eslint/no-explicit-any","Unexpected any. Specify a different type.","TSAnyKeyword","unexpectedAny",["84","85"],"'index' is defined but never used.","'token' is assigned a value but never used.","'test' is assigned a value but never used.",{"messageId":"86","fix":"87","desc":"88"},{"messageId":"89","fix":"90","desc":"91"},"suggestUnknown",{"range":"92","text":"93"},"Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.","suggestNever",{"range":"92","text":"94"},"Use `never` instead, this is useful when instantiating generic type parameters that you don't need to know the type of.",[1077,1080],"unknown","never"] \ No newline at end of file diff --git a/src/services/authService.ts b/src/services/authService.ts new file mode 100644 index 0000000..52e767e --- /dev/null +++ b/src/services/authService.ts @@ -0,0 +1,36 @@ +import { useUserStore } from "@/stores/user"; +import axios from "axios"; + +async function login(code: string): Promise { + const userStore = useUserStore(); + const baseApi = import.meta.env.VITE_API_BASE_URL; + const baseUrl = window.location.origin; + try { + const response = await axios.post(baseApi + "auth/discord", { + redirectUri: baseUrl + "/oauth2/callback", + code: code, + }); + + userStore.token = response.data.token; + const payload = userStore.getTokenPayload; + + userStore.userName = payload.sub as string; + userStore.discordId = payload.discord_id as string; + userStore.discriminator = payload.discriminator as string; + userStore.avatar = payload.avatar as string; + + userStore.loginFail = false; + console.log("Loggin success !"); + return true; + } catch (reason) { + console.log("Loggin fail !"); + console.log(reason); + userStore.token = ""; + userStore.userName = ""; + userStore.discordId = ""; + userStore.loginFail = true; + return false; + } +} + +export { login }; diff --git a/src/stores/user.ts b/src/stores/user.ts index 3b0b822..aae5023 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -31,38 +31,7 @@ export const useUserStore = defineStore("user", { return jose.decodeJwt(state.token); }, }, - actions: { - async login(code: string) { - const baseApi = import.meta.env.VITE_API_BASE_URL; - const baseUrl = window.location.origin; - try { - const response = await axios.post(baseApi + "auth/discord", { - redirectUri: baseUrl + "/oauth2/callback", - code: code, - }); - - this.token = response.data.token; - const payload = this.getTokenPayload; - - this.userName = payload.sub as string; - this.discordId = payload.discord_id as string; - this.discriminator = payload.discriminator as string; - this.avatar = payload.avatar as string; - - this.loginFail = false; - console.log("Loggin success !"); - return true; - } catch (reason) { - console.log("Loggin fail !"); - console.log(reason); - this.token = ""; - this.userName = ""; - this.discordId = ""; - this.loginFail = true; - return false; - } - }, - }, + actions: {}, persist: { storage: cookiesStorage, }, diff --git a/src/views/oauth/OauthCallbackView.vue b/src/views/oauth/OauthCallbackView.vue index e1c365c..e04bba2 100644 --- a/src/views/oauth/OauthCallbackView.vue +++ b/src/views/oauth/OauthCallbackView.vue @@ -12,6 +12,7 @@