Skip to content

Commit

Permalink
Merge pull request #6 from namidapoo/update(session)/auth-access-token
Browse files Browse the repository at this point in the history
feat: Sessionを拡張してgithubのアクセストークンを取得
  • Loading branch information
namidapoo authored Dec 26, 2024
2 parents dbc2d1c + bf26a29 commit 039c86e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/deploy-info-comment-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ jobs:
- name: Check if Deploy Workflow is Running
id: check_deploy
run: |
runs=$(gh run list --branch ${{ github.head_ref }} --workflow "Deploy to Cloudflare Pages" --json status --jq '.[] | select(.status == "in_progress")')
runs=$(gh run list --branch "${{ github.head_ref }}" \
--workflow "Deploy to Cloudflare Pages" \
--json status \
--jq '.[] | select(.status == "in_progress")' 2>/dev/null)
if [[ -n "$runs" ]]; then
echo "Deploy workflow is currently running. Exiting."
echo "DEPLOY_STATUS=running" >> $GITHUB_ENV
Expand Down
2 changes: 2 additions & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export default async function Home() {
const session = await auth();
if (!session?.user) return null;

console.log(session);

return (
<div className="flex min-h-dvh items-center justify-center bg-gradient-to-b from-pink-300 to-blue-300 p-4">
<div className="w-full max-w-md space-y-8 text-center">
Expand Down
21 changes: 19 additions & 2 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ import GitHub from "next-auth/providers/github";
import "next-auth/jwt";

export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [GitHub],
providers: [
GitHub({
authorization: {
param: {
scope: "repo read:user",
},
},
}),
],
callbacks: {
async jwt({ token, profile }) {
async jwt({ token, profile, account }) {
if (account) {
token.accessToken = account.access_token;
}
if (profile) {
const { login } = profile;
token.user = { ...token.user, login };
Expand All @@ -15,6 +26,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
async session({ session, token }) {
const { login } = token.user;
session.user = { ...session.user, login };
session.accessToken = token.accessToken;
return session;
},
},
Expand All @@ -24,18 +36,23 @@ declare module "next-auth" {
user: {
login: string;
} & DefaultSession["user"];
accessToken: string;
}
interface User {
login: string;
}
interface Profile {
login: string;
}
interface Account {
access_token: string;
}
}
declare module "next-auth/jwt" {
interface JWT {
user: {
login: string;
};
accessToken: string;
}
}

0 comments on commit 039c86e

Please sign in to comment.