Skip to content

Commit

Permalink
feat: authjs integrate (#951)
Browse files Browse the repository at this point in the history
* feat: oauth

Signed-off-by: Innei <i@innei.in>

* update

Signed-off-by: Innei <i@innei.in>

---------

Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei authored Aug 29, 2024
1 parent 22a606c commit b75cbff
Show file tree
Hide file tree
Showing 17 changed files with 985 additions and 212 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"dependencies": {
"@antv/g2": "^4.2.11",
"@auth/core": "0.34.2",
"@bytebase/vue-kbar": "0.1.8",
"@codemirror/commands": "6.6.0",
"@codemirror/lang-markdown": "6.2.5",
Expand Down
75 changes: 75 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/components/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,38 @@ export function MingcuteCopy2Line() {
</svg>
)
}

export function PhUsersThreeBold() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
viewBox="0 0 256 256"
>
<path
fill="currentColor"
d="M164.38 181.1a52 52 0 1 0-72.76 0a75.9 75.9 0 0 0-30 28.89a12 12 0 0 0 20.78 12a53 53 0 0 1 91.22 0a12 12 0 1 0 20.78-12a75.9 75.9 0 0 0-30.02-28.89M100 144a28 28 0 1 1 28 28a28 28 0 0 1-28-28m147.21 9.59a12 12 0 0 1-16.81-2.39c-8.33-11.09-19.85-19.59-29.33-21.64a12 12 0 0 1-1.82-22.91a20 20 0 1 0-24.78-28.3a12 12 0 1 1-21-11.6a44 44 0 1 1 73.28 48.35a92.2 92.2 0 0 1 22.85 21.69a12 12 0 0 1-2.39 16.8m-192.28-24c-9.48 2.05-21 10.55-29.33 21.65a12 12 0 0 1-19.19-14.45a92.4 92.4 0 0 1 22.85-21.69a44 44 0 1 1 73.28-48.35a12 12 0 1 1-21 11.6a20 20 0 1 0-24.78 28.3a12 12 0 0 1-1.82 22.91Z"
></path>
</svg>
)
}

export function MingcuteUserStarFill() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
viewBox="0 0 24 24"
>
<g fill="none" fill-rule="evenodd">
<path d="M24 0v24H0V0h24ZM12.594 23.258l-.012.002l-.071.035l-.02.004l-.014-.004l-.071-.036c-.01-.003-.019 0-.024.006l-.004.01l-.017.428l.005.02l.01.013l.104.074l.015.004l.012-.004l.104-.074l.012-.016l.004-.017l-.017-.427c-.002-.01-.009-.017-.016-.018Zm.264-.113l-.014.002l-.184.093l-.01.01l-.003.011l.018.43l.005.012l.008.008l.201.092c.012.004.023 0 .029-.008l.004-.014l-.034-.614c-.003-.012-.01-.02-.02-.022Zm-.715.002a.023.023 0 0 0-.027.006l-.006.014l-.034.614c0 .012.007.02.017.024l.015-.002l.201-.093l.01-.008l.003-.011l.018-.43l-.003-.012l-.01-.01l-.184-.092Z"></path>
<path
fill="currentColor"
d="M11 2a5 5 0 1 0 0 10a5 5 0 0 0 0-10Zm0 11c-2.395 0-4.575.694-6.178 1.671c-.8.49-1.484 1.065-1.978 1.69C2.358 16.977 2 17.713 2 18.5c0 .845.411 1.511 1.003 1.986c.56.45 1.299.748 2.084.956C6.665 21.859 8.771 22 11 22c.23 0 .46-.002.685-.005a1 1 0 0 0 .89-1.428A5.973 5.973 0 0 1 12 18c0-1.252.383-2.412 1.037-3.373a1 1 0 0 0-.72-1.557c-.43-.046-.87-.07-1.317-.07Zm7.864.997a1 1 0 0 0-1.728 0l-.91 1.562l-1.766.382a1 1 0 0 0-.534 1.644l1.204 1.348l-.182 1.798a1 1 0 0 0 1.398 1.016l1.654-.73l1.654.73a1 1 0 0 0 1.398-1.016l-.182-1.799l1.204-1.347a1 1 0 0 0-.534-1.644l-1.766-.382l-.91-1.562Z"
></path>
</g>
</svg>
)
}
5 changes: 4 additions & 1 deletion src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { WEB_URL } from '~/constants/env'
import { RouteName } from '~/router/name'
import { AppStore } from '~/stores/app'
import { UIStore } from '~/stores/ui'
import { RESTManager } from '~/utils'
import { removeToken, RESTManager } from '~/utils'
import { signOut } from '~/utils/authjs'

import { configs } from '../../configs'
import { useStoreRef } from '../../hooks/use-store-ref'
Expand Down Expand Up @@ -306,6 +307,8 @@ const LogoutAvatarButton = defineComponent({
const handleLogout = async (e: MouseEvent) => {
e.stopPropagation()
await RESTManager.api.user.logout.post({})
removeToken()
await signOut()
router.push({
name: RouteName.Login,
})
Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import App from './App'
import './index.css'

import { router } from './router'
import { attachTokenFromQuery } from './utils'
import { attachTokenFromQuery, RESTManager } from './utils'
import { authConfigManager, getCsrfToken } from './utils/authjs'

authConfigManager.setConfig({
basePath: '/auth',
baseUrl: RESTManager.endpoint,
credentials: 'include',
})

attachTokenFromQuery()

Expand Down
1 change: 1 addition & 0 deletions src/router/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export enum RouteName {

Maintain = 'maintain',
Other = 'other',
Reader = 'reader',
}
10 changes: 10 additions & 0 deletions src/router/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
OpenAIIcon,
PencilAltIcon,
PencilIcon,
PhUsersThreeBold,
PuzzlePieceIcon,
SubscribeIcon,
SymbolIcon,
Expand Down Expand Up @@ -186,6 +187,15 @@ export const routeForMenu: Array<RouteRecordRaw> = [
},
],
},
{
path: '/readers',
name: RouteName.Reader,
meta: {
title: '读者',
icon: <PhUsersThreeBold />,
},
component: () => import('../views/reader'),
},
{
path: '/files',
name: RouteName.File,
Expand Down
Loading

0 comments on commit b75cbff

Please sign in to comment.