Github auth
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { AuthorizationCode } from "simple-oauth2";
|
||||
|
||||
export const client = new AuthorizationCode({
|
||||
client: {
|
||||
id: process.env.GITHUB_CLIENT_ID!,
|
||||
secret: process.env.GITHUB_CLIENT_SECRET!,
|
||||
},
|
||||
auth: {
|
||||
tokenHost: "https://github.com",
|
||||
tokenPath: "/login/oauth/access_token",
|
||||
authorizePath: "/login/oauth/authorize",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
"use server";
|
||||
|
||||
import { client } from "@/core/auth/oauth";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function redirectAuth() {
|
||||
const authorizationUri = client.authorizeURL({
|
||||
redirect_uri: "http://localhost:3000/api/auth/callback",
|
||||
scope: "user:email",
|
||||
state: "random_state_string",
|
||||
});
|
||||
|
||||
redirect(authorizationUri);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { getIronSession } from "iron-session";
|
||||
|
||||
export const session = getIronSession({
|
||||
password: process.env.SESSION_PASSWORD!,
|
||||
cookieName: "nextjs_oauth_session",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
});
|
||||
Reference in New Issue
Block a user