Skip to content

Commit d4d636a

Browse files
committed
refactor(cli): fetch files from github instead of harcoding them in cli source code
1 parent 22a59b8 commit d4d636a

File tree

2 files changed

+4
-35
lines changed

2 files changed

+4
-35
lines changed

bin/cli.js

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ const main = defineCommand({
7575
path: envFilePath,
7676
});
7777

78-
// @ts-expect-error TODO: fix the typing
79-
const parsedConfig = new Map(Object.entries(dotEnvConfig.parsed));
78+
const parsedConfig = new Map(Object.entries(dotEnvConfig.parsed ?? {}));
8079

8180
if (!parsedConfig.has("NUXT_OAUTH_GITHUB_CLIENT_ID")) {
8281
parsedConfig.set("NUXT_OAUTH_GITHUB_CLIENT_ID", "\"\"");
@@ -101,38 +100,9 @@ const main = defineCommand({
101100
logger.warn("github demo already setup");
102101
}
103102
catch {
104-
await createFile(githubHandlerFilePath, `
105-
export default oauthGitHubEventHandler({
106-
config: {
107-
emailRequired: true,
108-
},
109-
async onSuccess(event, { user }) {
110-
const auth = useSlipAuth();
111-
112-
const [userId, sessionFromDb] = await auth.OAuthLoginUser({
113-
email: user.email,
114-
providerId: "github",
115-
providerUserId: user.id,
116-
ua: getRequestHeader(event, "User-Agent"),
117-
ip: getRequestIP(event),
118-
});
119-
120-
await setUserSession(event, {
121-
expires_at: sessionFromDb.expires_at,
122-
id: sessionFromDb.id,
123-
user: {
124-
id: userId,
125-
},
126-
});
127-
return sendRedirect(event, "/");
128-
},
129-
// Optional, will return a json error and 401 status code by default
130-
onError(event, error) {
131-
console.error("GitHub OAuth error:", error);
132-
return sendRedirect(event, "/");
133-
},
134-
});
135-
`);
103+
logger.info("fetching github handler on github");
104+
const githubFileRequest = await fetch("https://raw.githubusercontent.com/adrienZ/slip/refs/heads/master/playground/server/routes/auth/github.get.ts");
105+
await createFile(githubHandlerFilePath, await githubFileRequest.text());
136106
logger.success("github demo route setup");
137107
}
138108

pnpm-lock.yaml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)