Skip to content

Commit

Permalink
chore: upgrade to deno_kv_oauth@v0.2.4 (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Jun 22, 2023
1 parent b27cfbe commit bf236eb
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 124 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"stripe": "https://esm.sh/stripe@12.6.0",
"feed": "https://esm.sh/feed@4.2.2",
"fresh_charts/": "https://deno.land/x/fresh_charts@0.2.1/",
"deno_kv_oauth": "https://deno.land/x/deno_kv_oauth@v0.1.8-beta/mod.ts",
"kv_oauth": "https://deno.land/x/deno_kv_oauth@v0.2.4/mod.ts",
"@twind/core": "https://esm.sh/@twind/core@1.1.3"
}
}
5 changes: 3 additions & 2 deletions routes/_middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { walk } from "std/fs/walk.ts";
import { getSessionId } from "deno_kv_oauth";
import { getSessionId } from "kv_oauth";
import { setRedirectUrlCookie } from "@/utils/redirect.ts";

export interface State {
Expand All @@ -24,7 +24,8 @@ export async function handler(
return await ctx.next();
}

ctx.state.sessionId = getSessionId(req);
/** @todo Review once https://github.com/denoland/deno_kv_oauth/pull/126 is closed */
ctx.state.sessionId = await getSessionId(req) ?? undefined;

const res = await ctx.next();

Expand Down
6 changes: 3 additions & 3 deletions routes/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from "@/utils/db.ts";
import { stripe } from "@/utils/payments.ts";
import { State } from "./_middleware.ts";
import { handleCallback } from "deno_kv_oauth";
import { client } from "@/utils/kv_oauth.ts";
import { handleCallback } from "kv_oauth";
import { oauth2Client } from "@/utils/oauth2_client.ts";
import {
deleteRedirectUrlCookie,
getRedirectUrlCookie,
Expand Down Expand Up @@ -38,7 +38,7 @@ export const handler: Handlers<any, State> = {
async GET(req) {
const { response, accessToken, sessionId } = await handleCallback(
req,
client,
oauth2Client,
getRedirectUrlCookie(req.headers),
);

Expand Down
8 changes: 5 additions & 3 deletions routes/signin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { Handlers } from "$fresh/server.ts";
import type { State } from "./_middleware.ts";
import { redirect } from "@/utils/redirect.ts";
import { signIn } from "deno_kv_oauth";
import { client } from "@/utils/kv_oauth.ts";
import { signIn } from "kv_oauth";
import { oauth2Client } from "@/utils/oauth2_client.ts";

// deno-lint-ignore no-explicit-any
export const handler: Handlers<any, State> = {
Expand All @@ -12,6 +12,8 @@ export const handler: Handlers<any, State> = {
* If not logged in, it continues to rendering the login page.
*/
async GET(req, ctx) {
return ctx.state.sessionId ? redirect("/") : await signIn(req, client);
return ctx.state.sessionId
? redirect("/")
: await signIn(req, oauth2Client);
},
};
2 changes: 1 addition & 1 deletion routes/signout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Handlers } from "$fresh/server.ts";
import type { State } from "./_middleware.ts";
import { deleteUserBySession } from "@/utils/db.ts";
import { signOut } from "deno_kv_oauth";
import { signOut } from "kv_oauth";

// deno-lint-ignore no-explicit-any
export const handler: Handlers<any, State> = {
Expand Down
110 changes: 0 additions & 110 deletions utils/deno_kv_oauth.ts

This file was deleted.

4 changes: 0 additions & 4 deletions utils/kv_oauth.ts

This file was deleted.

4 changes: 4 additions & 0 deletions utils/oauth2_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2023 the Deno authors. All rights reserved. MIT license.
import { createGitHubOAuth2Client } from "kv_oauth";

export const oauth2Client = createGitHubOAuth2Client();

0 comments on commit bf236eb

Please sign in to comment.