Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Hono } from 'npm:hono';
import { cors } from 'npm:hono/cors';
import LuciaAuthMiddleware from 'https://esm.town/v/yawnxyz/hnCloneOAuth';
const app = new Hono();
// Enable CORS
app.use('*', cors({
origin: '*',
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowHeaders: ['Content-Type', 'Authorization'],
exposeHeaders: ['Content-Length', 'X-Lucia-Username'], // Add X-Lucia-Username to exposed headers
maxAge: 600,
credentials: true,
}));
const authMiddleware = new LuciaAuthMiddleware({
userTable: "lucia_users_1",
sessionTable: "lucia_sessions_1",
services: {
github: {
clientId: Deno.env.get("GITHUB_OAUTH_TEST1_CLIENT"),
clientSecret: Deno.env.get("GITHUB_OAUTH_TEST1_SECRET"),
userInfoUrl: "https://api.github.com/user"
},
google: {
clientId: Deno.env.get("GOOGLE_OAUTH_COVERSHEET_CLIENT"),
clientSecret: Deno.env.get("GOOGLE_OAUTH_COVERSHEET_SECRET"),
redirectUri: "https://yawnxyz-hnclonehtmx.web.val.run/auth/google/callback",
userInfoUrl: "https://openidconnect.googleapis.com/v1/userinfo"
}
}
});
app.use("*", authMiddleware.middleware());
authMiddleware.setupRoutes(app);
// Your routes go here
app.get('/', (c) => {
const user = c.get('user');
if (user) {
return c.html(`Hello, ${user.username}! <br><a href="/auth/logout">logout</a>`);
}
return c.html(`Hello, anonymous user! <br>
<a href="/auth/login">login</a> |
<a href="/auth/signup">signup</a> |
<a href="/auth/github">Sign in with GitHub</a> |
<a href="/auth/google">Sign in with Google</a>
<br>
<br>Note that Github and Google should work in principle, I just didn't configure them to work on this example in Google's API console or Github's thing :P
`);
});
export default app.fetch;
yawnxyz-simplelogin.web.val.run
September 4, 2024