mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-14 17:16:09 +00:00
# What does this PR do? Uses NextAuth to add github sign in support. ## Test Plan Start server with auth configured as in https://github.com/meta-llama/llama-stack/pull/2509 https://github.com/user-attachments/assets/61ff7442-f601-4b39-8686-5d0afb3b45ac
38 lines
1 KiB
TypeScript
38 lines
1 KiB
TypeScript
import { NextAuthOptions } from "next-auth";
|
|
import GithubProvider from "next-auth/providers/github";
|
|
|
|
export const authOptions: NextAuthOptions = {
|
|
providers: [
|
|
GithubProvider({
|
|
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
authorization: {
|
|
params: {
|
|
scope: "read:user user:email",
|
|
},
|
|
},
|
|
}),
|
|
],
|
|
debug: process.env.NODE_ENV === "development",
|
|
callbacks: {
|
|
async jwt({ token, account }) {
|
|
// Persist the OAuth access_token to the token right after signin
|
|
if (account) {
|
|
token.accessToken = account.access_token;
|
|
}
|
|
return token;
|
|
},
|
|
async session({ session, token }) {
|
|
// Send properties to the client, like an access_token from a provider.
|
|
session.accessToken = token.accessToken as string;
|
|
return session;
|
|
},
|
|
},
|
|
pages: {
|
|
signIn: "/auth/signin",
|
|
error: "/auth/signin", // Redirect errors to our custom page
|
|
},
|
|
session: {
|
|
strategy: "jwt",
|
|
},
|
|
};
|