feat: add github oauth configuration
This commit is contained in:
parent
ac667a243d
commit
4a979080af
3 changed files with 24 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { defineConfig } from 'astro/config';
|
import { defineConfig } from 'astro/config';
|
||||||
import vercel from '@astrojs/vercel';
|
import vercel from '@astrojs/vercel';
|
||||||
|
import auth from 'auth-astro';
|
||||||
import remarkDirective from 'remark-directive';
|
import remarkDirective from 'remark-directive';
|
||||||
import remarkGfm from 'remark-gfm';
|
import remarkGfm from 'remark-gfm';
|
||||||
import remarkSlug from 'remark-slug';
|
import remarkSlug from 'remark-slug';
|
||||||
|
|
@ -9,6 +10,7 @@ import remarkAside from './src/plugins/remark-aside.ts';
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
output: 'static',
|
output: 'static',
|
||||||
adapter: vercel(),
|
adapter: vercel(),
|
||||||
|
integrations: [auth()],
|
||||||
markdown: {
|
markdown: {
|
||||||
remarkPlugins: [
|
remarkPlugins: [
|
||||||
remarkGfm,
|
remarkGfm,
|
||||||
|
|
|
||||||
19
apps/blog/auth.config.ts
Normal file
19
apps/blog/auth.config.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import GitHub from '@auth/core/providers/github';
|
||||||
|
import { defineConfig } from 'auth-astro';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
providers: [
|
||||||
|
GitHub({
|
||||||
|
clientId: import.meta.env.GITHUB_CLIENT_ID,
|
||||||
|
clientSecret: import.meta.env.GITHUB_CLIENT_SECRET,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
callbacks: {
|
||||||
|
session({ session, token }) {
|
||||||
|
if (session.user && token.sub) {
|
||||||
|
session.user.id = token.sub;
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
3
apps/blog/src/lib/auth.ts
Normal file
3
apps/blog/src/lib/auth.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export function isAdmin(userId: string | undefined): boolean {
|
||||||
|
return userId === import.meta.env.ADMIN_GITHUB_ID;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue