-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue-sample): add vue sample project to demonstrate vue sdk
- Loading branch information
1 parent
0c0d9e6
commit 717e53b
Showing
17 changed files
with
744 additions
and
19 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,15 @@ | ||
/* eslint-env node */ | ||
require("@rushstack/eslint-patch/modern-module-resolution"); | ||
|
||
module.exports = { | ||
root: true, | ||
extends: [ | ||
"plugin:vue/vue3-essential", | ||
"eslint:recommended", | ||
"@vue/eslint-config-typescript/recommended", | ||
"@vue/eslint-config-prettier", | ||
], | ||
env: { | ||
"vue/setup-compiler-macros": true, | ||
}, | ||
}; |
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 @@ | ||
/// <reference types="vite/client" /> |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Logto Vue Sample</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
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,34 @@ | ||
{ | ||
"name": "@logto/vue-sample", | ||
"version": "0.1.7", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"preinstall": "npx only-allow pnpm", | ||
"precommit": "lint-staged", | ||
"start": "vite", | ||
"check": "vue-tsc --noEmit", | ||
"build": "pnpm check && rm -rf dist && vite build", | ||
"lint": "eslint --ext .vue,.ts src" | ||
}, | ||
"dependencies": { | ||
"@logto/vue": "^0.1.7", | ||
"vue": "^3.2.35", | ||
"vue-router": "^4.0.14" | ||
}, | ||
"devDependencies": { | ||
"@rushstack/eslint-patch": "^1.1.0", | ||
"@types/node": "^16.11.27", | ||
"@vitejs/plugin-vue": "^2.3.1", | ||
"@vue/eslint-config-prettier": "^7.0.0", | ||
"@vue/eslint-config-typescript": "^10.0.0", | ||
"@vue/tsconfig": "^0.1.3", | ||
"eslint": "^8.5.0", | ||
"eslint-plugin-vue": "^8.2.0", | ||
"lint-staged": "^12.3.4", | ||
"prettier": "^2.5.1", | ||
"typescript": "^4.6.2", | ||
"vite": "^2.9.5", | ||
"vue-tsc": "^0.34.7" | ||
} | ||
} |
Binary file not shown.
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,22 @@ | ||
<script setup lang="ts"> | ||
import { RouterView } from "vue-router"; | ||
</script> | ||
|
||
<template> | ||
<RouterView /> | ||
</template> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: sans-serif; | ||
background: #101419; | ||
color: #dadae0; | ||
text-align: center; | ||
} | ||
button { | ||
cursor: pointer; | ||
} | ||
</style> |
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 @@ | ||
export const baseUrl = window.location.origin; | ||
export const redirectUrl = `${baseUrl}/callback`; | ||
export const appId = "foo"; | ||
|
||
export const endpoint = "https://logto.dev"; // OIDC domain |
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,12 @@ | ||
import { createApp } from "vue"; | ||
import App from "./App.vue"; | ||
import router from "./router"; | ||
import { createLogto } from "@logto/vue"; | ||
import { appId, endpoint } from "./consts"; | ||
|
||
const app = createApp(App); | ||
|
||
app.use(createLogto, { appId, endpoint }); | ||
app.use(router); | ||
|
||
app.mount("#app"); |
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,27 @@ | ||
import { createRouter, createWebHistory } from "vue-router"; | ||
|
||
import CallbackView from "../views/CallbackView.vue"; | ||
import HomeView from "../views/HomeView.vue"; | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes: [ | ||
{ | ||
path: "/", | ||
name: "home", | ||
component: HomeView, | ||
}, | ||
{ | ||
path: "/callback", | ||
name: "callback", | ||
component: CallbackView, | ||
}, | ||
{ | ||
path: "/protected-resource", | ||
name: "protected-resource", | ||
component: () => import("../views/ProtectedResourceView.vue"), | ||
}, | ||
], | ||
}); | ||
|
||
export default router; |
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 @@ | ||
declare module "*.vue"; |
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,16 @@ | ||
<script lang="ts"> | ||
import { useHandleSignInCallback } from "@logto/vue"; | ||
export default { | ||
setup() { | ||
const { isLoading } = useHandleSignInCallback(); | ||
return { | ||
isLoading, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<template> | ||
<p v-if="isLoading">Redirecting...</p> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<script lang="ts"> | ||
import { useLogto, type IdTokenClaims } from "@logto/vue"; | ||
import { RouterLink } from "vue-router"; | ||
import { ref, watchEffect } from "vue"; | ||
import { baseUrl, redirectUrl } from "../consts"; | ||
export default { | ||
setup() { | ||
const { isAuthenticated, getIdTokenClaims, signIn, signOut } = useLogto(); | ||
const idTokenClaims = ref<IdTokenClaims>(); | ||
const onClickSignIn = () => { | ||
void signIn(redirectUrl); | ||
}; | ||
const onClickSignOut = () => { | ||
void signOut(baseUrl); | ||
}; | ||
watchEffect(async () => { | ||
if (isAuthenticated.value) { | ||
const claims = getIdTokenClaims(); | ||
idTokenClaims.value = claims; | ||
} | ||
}); | ||
return { | ||
idTokenClaims, | ||
isAuthenticated, | ||
onClickSignIn, | ||
onClickSignOut, | ||
}; | ||
}, | ||
components: { | ||
RouterLink, | ||
}, | ||
}; | ||
</script> | ||
<template> | ||
<div class="container"> | ||
<h3>Logto Vue Sample</h3> | ||
<button v-if="!isAuthenticated" @click="onClickSignIn">Sign In</button> | ||
<button v-else @click="onClickSignOut">Sign Out</button> | ||
<div v-if="isAuthenticated && idTokenClaims"> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr v-for="(value, key) in idTokenClaims" v-bind:key="key"> | ||
<td>{{ key }}</td> | ||
<td>{{ value }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<RouterLink to="/protected-resource">View Protected Resource</RouterLink> | ||
</div> | ||
</div> | ||
</template> | ||
<style lang="scss"> | ||
.container { | ||
padding: 20px; | ||
} | ||
.table { | ||
margin: 50px auto; | ||
table-layout: fixed; | ||
width: 800px; | ||
border: 1px solid #333; | ||
border-spacing: 0; | ||
th, | ||
td { | ||
padding: 10px; | ||
word-wrap: break-word; | ||
border: 1px solid #333; | ||
} | ||
th { | ||
font-weight: bold; | ||
} | ||
} | ||
</style> |
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,27 @@ | ||
<script lang="ts"> | ||
import { useLogto } from "@logto/vue"; | ||
import { onMounted } from "vue"; | ||
import { redirectUrl } from "../consts"; | ||
export default { | ||
setup() { | ||
const { isAuthenticated, isLoading, signIn } = useLogto(); | ||
onMounted(() => { | ||
if (!isAuthenticated.value && !isLoading.value) { | ||
void signIn(redirectUrl); | ||
} | ||
}); | ||
return { | ||
isAuthenticated, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<template> | ||
<p v-if="isAuthenticated"> | ||
Protected resource is only visible after sign-in. | ||
</p> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "@vue/tsconfig/tsconfig.web.json", | ||
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"], | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
|
||
"references": [ | ||
{ | ||
"path": "./tsconfig.vite-config.json" | ||
} | ||
] | ||
} |
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,8 @@ | ||
{ | ||
"extends": "@vue/tsconfig/tsconfig.node.json", | ||
"include": ["vite.config.*"], | ||
"compilerOptions": { | ||
"composite": true, | ||
"types": ["node"] | ||
} | ||
} |
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,22 @@ | ||
import { fileURLToPath, URL } from "url"; | ||
|
||
import { defineConfig } from "vite"; | ||
import vue from "@vitejs/plugin-vue"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [vue()], | ||
resolve: { | ||
alias: { | ||
"@": fileURLToPath(new URL("./src", import.meta.url)), | ||
}, | ||
}, | ||
optimizeDeps: { | ||
include: ["@logto/vue"], | ||
}, | ||
build: { | ||
commonjsOptions: { | ||
include: [/linked-dep/, /node_modules/], | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.