-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from nbtca/logto
Add login with logto
- Loading branch information
Showing
19 changed files
with
717 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
VITE_LOGTO_CALLBACK_URL=http://localhost:5173/callback | ||
VITE_LOGTO_REDIRECT_URL=http://localhost:5173 | ||
VITE_LOGTO_ENDPOINT=https://auth.app.nbtca.space | ||
VITE_LOGTO_APP_ID=h2ejkkfwdtjjpemb021ro | ||
VITE_LOGTO_RESOURCE=https://api.nbtca.space/v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
VITE_LOGTO_CALLBACK_URL=https://repair.nbtca.space/callback | ||
VITE_LOGTO_REDIRECT_URL=https://repair.nbtca.space:5173 | ||
VITE_LOGTO_ENDPOINT=https://auth.app.nbtca.space | ||
VITE_LOGTO_APP_ID=h2ejkkfwdtjjpemb021ro | ||
VITE_LOGTO_RESOURCE=https://api.nbtca.space/v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"cellsm", | ||
"innerlg", | ||
"innersm", | ||
"Logto", | ||
"sclass" | ||
], | ||
"testing.automaticallyOpenPeekView": "never" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script setup lang="ts"> | ||
import router from "@/router" | ||
import { useAccountStore } from "@/stores/account" | ||
import { useLogto } from "@logto/vue" | ||
const store = useAccountStore() | ||
const { signOut } = useLogto() | ||
const logOut = () => { | ||
const store = useAccountStore() | ||
store.account = {} | ||
store.token = "" | ||
signOut(import.meta.env.VITE_LOGTO_REDIRECT_URL) | ||
} | ||
</script> | ||
<template> | ||
<button @click="logOut"> | ||
<slot></slot> | ||
</button> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<script setup lang="ts"> | ||
import logOut from "@/composables/LogOut" | ||
import type Member from "@/models/member" | ||
import router from "@/router" | ||
import { useAccountStore } from "@/stores/account" | ||
import Axios from "@/utils/axios" | ||
import { useHandleSignInCallback, useLogto } from "@logto/vue" | ||
import { ref, onMounted } from "vue" | ||
const store = useAccountStore() | ||
const { signIn, signOut, isAuthenticated, fetchUserInfo, getAccessToken } = useLogto() | ||
const authenticateFailed = ref(false) | ||
const { isLoading } = useHandleSignInCallback(async () => { | ||
const token = await getAccessToken(import.meta.env.VITE_LOGTO_RESOURCE) | ||
const res = await window.fetch("/api/member/token/logto", { | ||
headers: { | ||
Authorization: "Bearer " + token, | ||
}, | ||
}) | ||
const body = await res.json() | ||
if ("token" in body && "memberId" in body && "role" in body) { | ||
store.account = body as Member | ||
store.token = body.token | ||
if (body.role.includes("inactive")) { | ||
router.push("/activate") | ||
router.push("/activate") | ||
} else { | ||
router.push("/Events") | ||
} | ||
} else { | ||
setTimeout(() => { | ||
signOut(import.meta.env.VITE_LOGTO_REDIRECT_URL) | ||
}, 2000) | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="p-3"> | ||
<p v-if="isLoading">页面跳转中。。。</p> | ||
<p v-if="authenticateFailed">认证失败,跳转至登入页面。</p> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.