Saltearse al contenido

effect/github

Esta página aún no está disponible en tu idioma.

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:67^

Provides GitHub OAuth authentication effects for the StudioCMS API.

This service handles the OAuth flow with GitHub, including:

  • Initializing the OAuth session and redirecting users to GitHub for authorization.
  • Validating the authorization code returned by GitHub and fetching user data.
  • Handling the callback from GitHub, including:
    • Linking OAuth accounts to existing users.
    • Creating new users from GitHub profile data.
    • Verifying user email addresses.
    • Creating user sessions and redirecting to appropriate pages.
  • Depends on session management, user library, email verification, and SDK core services.
  • Handles both first-time setup and linking additional OAuth providers to existing accounts.
const githubOAuth = new GitHubOAuthAPI();
yield* githubOAuth.initSession(context);
yield* githubOAuth.initCallback(context);
  • Session
  • SDKCore
  • VerifyEmail
  • User
  • { initCallback: (context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never>; initSession: (context: APIContext) => Effect<Response, SessionError, never>; } & { _tag: "GitHubOAuthAPI"; }

new GitHubOAuthAPI(_: {
initCallback: (context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never>;
initSession: (context: APIContext) => Effect<Response, SessionError, never>;
}): GitHubOAuthAPI

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:26559

(context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never> = ...

(context: APIContext) => Effect<Response, SessionError, never> = ...

GitHubOAuthAPI

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).constructor

readonly _tag: "GitHubOAuthAPI";

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:26560

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
})._tag

initCallback: (context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never>;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:117^

APIContext

Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never>

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).initCallback

initSession: (context: APIContext) => Effect<Response, SessionError, never>;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:106^

APIContext

Effect<Response, SessionError, never>

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).initSession

readonly static _op: "Tag";

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:28

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
})._op

readonly static [ChannelTypeId]: VarianceStruct<never, unknown, never, unknown, GitHubOAuthAPI, unknown, GitHubOAuthAPI>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Channel.d.ts:108

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[ChannelTypeId]

readonly static [EffectTypeId]: VarianceStruct<GitHubOAuthAPI, never, GitHubOAuthAPI>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:195

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[EffectTypeId]

static optional [ignoreSymbol]: TagUnifyIgnore;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:41

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[ignoreSymbol]

readonly static [SinkTypeId]: VarianceStruct<GitHubOAuthAPI, unknown, never, never, GitHubOAuthAPI>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Sink.d.ts:82

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[SinkTypeId]

readonly static [STMTypeId]: {
_A: Covariant<GitHubOAuthAPI>;
_E: Covariant<never>;
_R: Covariant<GitHubOAuthAPI>;
};

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/STM.d.ts:136

readonly _A: Covariant<GitHubOAuthAPI>;
readonly _E: Covariant<never>;
readonly _R: Covariant<GitHubOAuthAPI>;
Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[STMTypeId]

readonly static [StreamTypeId]: VarianceStruct<GitHubOAuthAPI, never, GitHubOAuthAPI>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Stream.d.ts:111

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[StreamTypeId]

readonly static [TagTypeId]: {
_Identifier: Invariant<GitHubOAuthAPI>;
_Service: Invariant<GitHubOAuthAPI>;
};

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:31

readonly _Identifier: Invariant<GitHubOAuthAPI>;
readonly _Service: Invariant<GitHubOAuthAPI>;
Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[TagTypeId]

static optional [typeSymbol]: unknown;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:39

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[typeSymbol]

static optional [unifySymbol]: TagUnify<Class<GitHubOAuthAPI, "GitHubOAuthAPI", {
dependencies: readonly [Layer<VerifyEmail, Error, never>, Layer<HttpClient, never, never>];
effect: Effect<{
initCallback: (context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never>;
initSession: (context: APIContext) => Effect<Response, SessionError, never>;
}, SessionError | UserError, VerifyEmail | HttpClient>;
}>>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:40

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[unifySymbol]

readonly static Default: Layer<GitHubOAuthAPI, Error | SessionError | UserError, never>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:26570

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).Default

readonly static DefaultWithoutDependencies: Layer<GitHubOAuthAPI, SessionError | UserError, VerifyEmail | HttpClient>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:26569

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).DefaultWithoutDependencies

readonly static Identifier: GitHubOAuthAPI;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:30

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).Identifier

readonly static key: "GitHubOAuthAPI";

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:38

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).key

readonly static make: (_: {
initCallback: (context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never>;
initSession: (context: APIContext) => Effect<Response, SessionError, never>;
}) => GitHubOAuthAPI;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:26563

(context: APIContext) => Effect<Response, Error | LibSQLDatabaseError | SDKCoreError, never> = ...

(context: APIContext) => Effect<Response, SessionError, never> = ...

GitHubOAuthAPI

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).make

static ProviderCookieName: string = 'github_oauth_state';

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:236^

static ProviderID: string = 'github';

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:235^

readonly static Service: GitHubOAuthAPI;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:29

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).Service

readonly static optional stack: string;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:37

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).stack

readonly static use: <X>(body: (_: GitHubOAuthAPI) => X) => [X] extends [Effect<A, E, R>] ? Effect<A, E,
| GitHubOAuthAPI
| R> : [X] extends [PromiseLike<A>] ? Effect<A, UnknownException, GitHubOAuthAPI> : Effect<X, never, GitHubOAuthAPI>;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:26562

X

(_: GitHubOAuthAPI) => X

[X] extends [Effect<A, E, R>] ? Effect<A, E, | GitHubOAuthAPI | R> : [X] extends [PromiseLike<A>] ? Effect<A, UnknownException, GitHubOAuthAPI> : Effect<X, never, GitHubOAuthAPI>

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).use

static iterator: EffectGenerator<Tag<GitHubOAuthAPI, GitHubOAuthAPI>>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Effect.d.ts:137

EffectGenerator<Tag<GitHubOAuthAPI, GitHubOAuthAPI>>

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[iterator]

static NodeInspectSymbol: unknown

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Inspectable.d.ts:22

unknown

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).[NodeInspectSymbol]

static context(self: GitHubOAuthAPI): Context<GitHubOAuthAPI>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:36

GitHubOAuthAPI

Context<GitHubOAuthAPI>

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).context

static of(self: GitHubOAuthAPI): GitHubOAuthAPI

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Context.d.ts:35

GitHubOAuthAPI

GitHubOAuthAPI

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).of

static pipe<A>(this: A): A

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:10

A

A

A

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B>(this: A, ab: (_: A) => B): B

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:11

A

B = never

A

(_: A) => B

B

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C): C

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:12

A

B = never

C = never

A

(_: A) => B

(_: B) => C

C

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D): D

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:13

A

B = never

C = never

D = never

A

(_: A) => B

(_: B) => C

(_: C) => D

D

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E): E

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:14

A

B = never

C = never

D = never

E = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

E

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F): F

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:15

A

B = never

C = never

D = never

E = never

F = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

F

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G): G

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:16

A

B = never

C = never

D = never

E = never

F = never

G = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

G

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H): H

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:17

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

H

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I): I

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:18

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

I

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J): J

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:19

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

J

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K): K

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:20

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

K

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L): L

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:21

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

L

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M): M

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:22

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

M

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N): N

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:23

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

N

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O): O

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:24

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

O

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P): P

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:25

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

P

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q): Q

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:26

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

Q

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R): R

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:27

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

R

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S): S

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:28

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

S

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S,
st: (_: S) => T): T

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:29

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

T = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

(_: S) => T

T

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S,
st: (_: S) => T,
tu: (_: T) => U): U

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:30

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

T = never

U = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

(_: S) => T

(_: T) => U

U

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S,
st: (_: S) => T,
tu: (_: T) => U): U

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:31

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

T = never

U = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

(_: S) => T

(_: T) => U

U

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).pipe

static toJSON(): unknown

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Inspectable.d.ts:21

unknown

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).toJSON

static toString(): string

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Inspectable.d.ts:20

string

Effect.Service<GitHubOAuthAPI>()('GitHubOAuthAPI', {
dependencies: [VerifyEmail.Default, Platform.FetchHttpClient.layer],
effect: genLogger('studiocms/routes/api/auth/github/effect')(function () {
const [
sdk,
fetchClient,
{ setOAuthSessionTokenCookie, createUserSession },
{ isEmailVerified, sendVerificationEmail },
{ getUserData, createOAuthUser },
] = yield Effect.all([SDKCore, Platform.HttpClient.HttpClient, Session, VerifyEmail, User]);
const { CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = GITHUB;
const github = new GitHub(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
const validateAuthCode = (code: string) =>
genLogger('studiocms/routes/api/auth/github/effect.validateAuthCode')(function () {
const tokens = yield Effect.tryPromise(() => github.validateAuthorizationCode(code));
return yield fetchClient
.get('https://api.github.com/user', {
headers: {
Authorization: Bearer ${tokens.accessToken},
},
})
.pipe(
Effect.flatMap(Platform.HttpClientResponse.schemaBodyJson(GitHubUser)),
Effect.catchAll((error) =>
Effect.fail(
new ValidateAuthCodeError({
provider: GitHubOAuthAPI.ProviderID,
message: Failed to fetch user info: ${error.message},
})
)
)
);
});
return {
initSession: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initSession')(function () {
const state = generateState();
const scopes = ['user:email', 'repo'];
const url = github.createAuthorizationURL(state, scopes);
yield setOAuthSessionTokenCookie(context, GitHubOAuthAPI.ProviderCookieName, state);
return context.redirect(url.toString());
}),
initCallback: (context: APIContext) =>
genLogger('studiocms/routes/api/auth/github/effect.initCallback')(function () {
const { cookies, redirect } = context;
const [code, state, storedState] = yield Effect.all([
getUrlParam(context, 'code'),
getUrlParam(context, 'state'),
getCookie(context, GitHubOAuthAPI.ProviderCookieName),
]);
if (!code || !state || !storedState || state !== storedState) {
return redirect(StudioCMSRoutes.authLinks.loginURL);
}
const githubUser = yield validateAuthCode(code);
const { id: githubUserId, login: githubUsername } = githubUser;
const existingOAuthAccount = yield sdk.AUTH.oAuth.searchProvidersForId(
GitHubOAuthAPI.ProviderID,
${githubUserId}
);
if (existingOAuthAccount) {
const user = yield sdk.GET.users.byId(existingOAuthAccount.userId);
if (!user) {
return new Response('User not found', { status: 404 });
}
const isEmailAccountVerified = yield isEmailVerified(user);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(user.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
const loggedInUser = yield getUserData(context);
const linkNewOAuth = !!cookies.get(LinkNewOAuthCookieName)?.value;
if (loggedInUser.user && linkNewOAuth) {
const existingUser = yield sdk.GET.users.byId(loggedInUser.user.id);
if (existingUser) {
yield sdk.AUTH.oAuth.create({
userId: existingUser.id,
provider: GitHubOAuthAPI.ProviderID,
providerUserId: ${githubUserId},
});
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(existingUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}
}
const newUser = yield createOAuthUser(
{
id: crypto.randomUUID(),
username: githubUsername,
email: githubUser.email || null,
name: githubUser.name || githubUsername,
avatar: githubUser.avatar_url,
createdAt: new Date(),
url: githubUser.blog || null,
emailVerified: false,
notifications: null,
password: null,
updatedAt: new Date(),
},
{ provider: GitHubOAuthAPI.ProviderID, providerUserId: ${githubUserId} }
);
if ('error' in newUser) {
return new Response('Error creating user', { status: 500 });
}
// FIRST-TIME-SETUP
if (config.dbStartPage) {
return redirect('/done');
}
yield sendVerificationEmail(newUser.id, true);
const existingUser = yield sdk.GET.users.byId(newUser.id);
const isEmailAccountVerified = yield isEmailVerified(existingUser);
// If Mailer is enabled, is the user verified?
if (!isEmailAccountVerified) {
return new Response('Email not verified, please verify your account first.', {
status: 400,
});
}
yield createUserSession(newUser.id, context);
return redirect(StudioCMSRoutes.mainLinks.dashboardIndex);
}),
};
}),
}).toString

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:23^

Represents a GitHub user profile as returned by the GitHub API.

  • { id: number; } & { html_url: string; } & { login: string; } & { avatar_url: string; } & { name: string; } & { blog: string; } & { email: string; }

new GitHubUser(props: {
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
}, options?: MakeOptions): GitHubUser

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4265

string = Schema.String

string = ...

string = ...

string = Schema.String

number = Schema.Number

string = Schema.String

string = ...

MakeOptions

GitHubUser

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).constructor

readonly avatar_url: string = Schema.String;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:27^

The URL to the user’s avatar image.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).avatar_url

readonly optional blog: string;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:29^

The user’s blog URL.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).blog

readonly optional email: string;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:30^

The user’s public email address.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).email

readonly html_url: string = Schema.String;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:25^

The URL to the user’s GitHub profile.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).html_url

readonly id: number = Schema.Number;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:24^

The unique identifier for the user.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).id

readonly login: string = Schema.String;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:26^

The user’s GitHub username.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).login

readonly optional name: string;

Defined in: studiocms/packages/@studiocms/github/src/effect/github.ts:28^

The user’s display name.

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).name

readonly static [TypeId]: {
_A: Invariant<GitHubUser>;
_I: Invariant<{
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
}>;
_R: Covariant<never>;
};

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:160

readonly _A: Invariant<GitHubUser>;
readonly _I: Invariant<{
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
}>;
readonly _R: Covariant<never>;
Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).[TypeId]

readonly static ast: Transformation;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4267

3.10.0

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).ast

readonly static Context: never;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:63

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).Context

readonly static Encoded: {
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
};

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:62

avatar_url: string;
optional blog: string;
optional email: string;
html_url: string;
id: number;
login: string;
optional name: string;
Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).Encoded

readonly static fields: {
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
};

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4270

readonly avatar_url: typeof String$ = Schema.String;
readonly blog: optional<typeof String$>;
readonly email: optional<typeof String$>;
readonly html_url: typeof String$ = Schema.String;
readonly id: typeof Number$ = Schema.Number;
readonly login: typeof String$ = Schema.String;
readonly name: optional<typeof String$>;
Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).fields

readonly static identifier: string;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4273

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).identifier

readonly static Type: GitHubUser;

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:61

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).Type

static annotations(annotations: Schema<GitHubUser>): SchemaClass<GitHubUser, {
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
}, never>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4269

Merges a set of new annotations with existing ones, potentially overwriting any duplicates.

Schema<GitHubUser>

SchemaClass<GitHubUser, { avatar_url: string; blog: string; email: string; html_url: string; id: number; login: string; name: string; }, never>

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).annotations

static extend<Extended>(identifier: string): <NewFields>(fields: NewFields | HasFields<NewFields>, annotations?: ClassAnnotations<Extended, { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }>) => [Extended] extends [never] ? "Missing `Self` generic - use `class Self extends Base.extend<Self>()({ ... })`" : Class<Extended, {
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
} & NewFields, {
avatar_url: string;
html_url: string;
id: number;
login: string;
} & {
blog: string;
email: string;
name: string;
} & { readonly [K in string | number | symbol as Key<NewFields, K>]: Encoded<NewFields[K]> } & { readonly [K in string | number | symbol as Key<NewFields, K>]?: Encoded<NewFields[K]> }, Context<NewFields[keyof NewFields]>, {
id: number;
} & {
html_url: string;
} & {
login: string;
} & {
avatar_url: string;
} & {
name: string;
} & {
blog: string;
} & {
email: string;
} & Constructor<NewFields>, GitHubUser, {}>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4296

Extended = never

string

Function

NewFields extends Fields

NewFields | HasFields<NewFields>

ClassAnnotations<Extended, { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }>

[Extended] extends [never] ? "Missing `Self` generic - use `class Self extends Base.extend<Self>()({ ... })`" : Class<Extended, { avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$>; } & NewFields, { avatar_url: string; html_url: string; id: number; login: string; } & { blog: string; email: string; name: string; } & { readonly [K in string | number | symbol as Key<NewFields, K>]: Encoded<NewFields[K]> } & { readonly [K in string | number | symbol as Key<NewFields, K>]?: Encoded<NewFields[K]> }, Context<NewFields[keyof NewFields]>, { id: number; } & { html_url: string; } & { login: string; } & { avatar_url: string; } & { name: string; } & { blog: string; } & { email: string; } & Constructor<NewFields>, GitHubUser, {}>

import { Schema } from "effect"
class MyClass extends Schema.Class<MyClass>("MyClass")({
myField: Schema.String
}) {
myMethod() {
return this.myField + "my"
}
}
class NextClass extends MyClass.extend<NextClass>("NextClass")({
nextField: Schema.Number
}) {
nextMethod() {
return this.myMethod() + this.myField + this.nextField
}
}
Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).extend

static make<C>(this: C, ...args: ConstructorParameters<C>): InstanceType<C>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4268

C extends (…args: any[]) => any

C

ConstructorParameters<C>

InstanceType<C>

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).make

static pipe<A>(this: A): A

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:10

A

A

A

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B>(this: A, ab: (_: A) => B): B

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:11

A

B = never

A

(_: A) => B

B

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C): C

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:12

A

B = never

C = never

A

(_: A) => B

(_: B) => C

C

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D): D

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:13

A

B = never

C = never

D = never

A

(_: A) => B

(_: B) => C

(_: C) => D

D

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E): E

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:14

A

B = never

C = never

D = never

E = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

E

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F): F

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:15

A

B = never

C = never

D = never

E = never

F = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

F

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G): G

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:16

A

B = never

C = never

D = never

E = never

F = never

G = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

G

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H): H

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:17

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

H

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I): I

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:18

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

I

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J): J

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:19

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

J

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K): K

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:20

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

K

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L): L

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:21

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

L

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M): M

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:22

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

M

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N): N

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:23

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

N

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O): O

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:24

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

O

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P): P

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:25

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

P

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q): Q

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:26

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

Q

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R): R

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:27

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

R

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S): S

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:28

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

S

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S,
st: (_: S) => T): T

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:29

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

T = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

(_: S) => T

T

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S,
st: (_: S) => T,
tu: (_: T) => U): U

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:30

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

T = never

U = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

(_: S) => T

(_: T) => U

U

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe
static pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(
this: A,
ab: (_: A) => B,
bc: (_: B) => C,
cd: (_: C) => D,
de: (_: D) => E,
ef: (_: E) => F,
fg: (_: F) => G,
gh: (_: G) => H,
hi: (_: H) => I,
ij: (_: I) => J,
jk: (_: J) => K,
kl: (_: K) => L,
lm: (_: L) => M,
mn: (_: M) => N,
no: (_: N) => O,
op: (_: O) => P,
pq: (_: P) => Q,
qr: (_: Q) => R,
rs: (_: R) => S,
st: (_: S) => T,
tu: (_: T) => U): U

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Pipeable.d.ts:31

A

B = never

C = never

D = never

E = never

F = never

G = never

H = never

I = never

J = never

K = never

L = never

M = never

N = never

O = never

P = never

Q = never

R = never

S = never

T = never

U = never

A

(_: A) => B

(_: B) => C

(_: C) => D

(_: D) => E

(_: E) => F

(_: F) => G

(_: G) => H

(_: H) => I

(_: I) => J

(_: J) => K

(_: K) => L

(_: L) => M

(_: M) => N

(_: N) => O

(_: O) => P

(_: P) => Q

(_: Q) => R

(_: R) => S

(_: S) => T

(_: T) => U

U

Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).pipe

static transformOrFail<Transformed>(identifier: string): <NewFields, R2, R3>(fields: NewFields, options: {
decode: (input: {
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
}, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }, ParseIssue, R2>;
encode: (input: { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }, options: ParseOptions, ast: Transformation) => Effect<{
id: number;
} & {
html_url: string;
} & {
login: string;
} & {
avatar_url: string;
} & {
name: string;
} & {
blog: string;
} & {
email: string;
}, ParseIssue, R3>;
}, annotations?: ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }>) => [Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFail<Self>()({ ... })`" : Class<Transformed, {
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
} & NewFields, Encoded<{
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
}>, R2 | R3 | Context<NewFields[keyof NewFields]>, {
id: number;
} & {
html_url: string;
} & {
login: string;
} & {
avatar_url: string;
} & {
name: string;
} & {
blog: string;
} & {
email: string;
} & Constructor<NewFields>, GitHubUser, {}>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4326

Transformed = never

string

Function

NewFields extends Fields

R2

R3

NewFields

(input: { avatar_url: string; blog: string; email: string; html_url: string; id: number; login: string; name: string; }, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }, ParseIssue, R2>

(input: { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }, options: ParseOptions, ast: Transformation) => Effect<{ id: number; } & { html_url: string; } & { login: string; } & { avatar_url: string; } & { name: string; } & { blog: string; } & { email: string; }, ParseIssue, R3>

ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }>

[Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFail<Self>()({ ... })`" : Class<Transformed, { avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$>; } & NewFields, Encoded<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$>; }>, R2 | R3 | Context<NewFields[keyof NewFields]>, { id: number; } & { html_url: string; } & { login: string; } & { avatar_url: string; } & { name: string; } & { blog: string; } & { email: string; } & Constructor<NewFields>, GitHubUser, {}>

import { Effect, Schema } from "effect"
class MyClass extends Schema.Class<MyClass>("MyClass")({
myField: Schema.String
}) {
myMethod() {
return this.myField + "my"
}
}
class NextClass extends MyClass.transformOrFail<NextClass>("NextClass")({
nextField: Schema.Number
}, {
decode: (i) =>
Effect.succeed({
myField: i.myField,
nextField: i.myField.length
}),
encode: (a) => Effect.succeed({ myField: a.myField })
}) {
nextMethod() {
return this.myMethod() + this.myField + this.nextField
}
}
Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).transformOrFail

static transformOrFailFrom<Transformed>(identifier: string): <NewFields, R2, R3>(fields: NewFields, options: {
decode: (input: {
avatar_url: string;
blog: string;
email: string;
html_url: string;
id: number;
login: string;
name: string;
}, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: ({ avatar_url: string; html_url: string; id: number; login: string } & { blog?: string; email?: string; name?: string } & { readonly [K in string | number | symbol as Key<NewFields, K>]: Encoded<NewFields[K]> } & { readonly [K in string | number | symbol as Key<NewFields, K>]?: Encoded<(...)[(...)]> })[K] }, ParseIssue, R2>;
encode: (input: { [K in string | number | symbol]: ({ avatar_url: string; html_url: string; id: number; login: string } & { blog?: string; email?: string; name?: string } & { readonly [K in string | number | symbol as Key<NewFields, K>]: Encoded<NewFields[K]> } & { readonly [K in string | number | symbol as Key<NewFields, K>]?: Encoded<NewFields[K]> })[K] }, options: ParseOptions, ast: Transformation) => Effect<Encoded<{
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
}>, ParseIssue, R3>;
}, annotations?: ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }>) => [Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFailFrom<Self>()({ ... })`" : Class<Transformed, {
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
} & NewFields, Encoded<{
avatar_url: typeof String$;
blog: optional<typeof String$>;
email: optional<typeof String$>;
html_url: typeof String$;
id: typeof Number$;
login: typeof String$;
name: optional<typeof String$>;
}>, R2 | R3 | Context<NewFields[keyof NewFields]>, {
id: number;
} & {
html_url: string;
} & {
login: string;
} & {
avatar_url: string;
} & {
name: string;
} & {
blog: string;
} & {
email: string;
} & Constructor<NewFields>, GitHubUser, {}>

Defined in: node_modules/.pnpm/effect@3.17.9/node_modules/effect/dist/dts/Schema.d.ts:4359

Transformed = never

string

Function

NewFields extends Fields

R2

R3

NewFields

(input: { avatar_url: string; blog: string; email: string; html_url: string; id: number; login: string; name: string; }, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: ({ avatar_url: string; html_url: string; id: number; login: string } & { blog?: string; email?: string; name?: string } & { readonly [K in string | number | symbol as Key<NewFields, K>]: Encoded<NewFields[K]> } & { readonly [K in string | number | symbol as Key<NewFields, K>]?: Encoded<(…)[(…)]> })[K] }, ParseIssue, R2>

(input: { [K in string | number | symbol]: ({ avatar_url: string; html_url: string; id: number; login: string } & { blog?: string; email?: string; name?: string } & { readonly [K in string | number | symbol as Key<NewFields, K>]: Encoded<NewFields[K]> } & { readonly [K in string | number | symbol as Key<NewFields, K>]?: Encoded<NewFields[K]> })[K] }, options: ParseOptions, ast: Transformation) => Effect<Encoded<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$>; }>, ParseIssue, R3>

ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$> } & NewFields>[K] }>

[Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFailFrom<Self>()({ ... })`" : Class<Transformed, { avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$>; } & NewFields, Encoded<{ avatar_url: typeof String$; blog: optional<typeof String$>; email: optional<typeof String$>; html_url: typeof String$; id: typeof Number$; login: typeof String$; name: optional<typeof String$>; }>, R2 | R3 | Context<NewFields[keyof NewFields]>, { id: number; } & { html_url: string; } & { login: string; } & { avatar_url: string; } & { name: string; } & { blog: string; } & { email: string; } & Constructor<NewFields>, GitHubUser, {}>

import { Effect, Schema } from "effect"
class MyClass extends Schema.Class<MyClass>("MyClass")({
myField: Schema.String
}) {
myMethod() {
return this.myField + "my"
}
}
class NextClass extends MyClass.transformOrFailFrom<NextClass>("NextClass")({
nextField: Schema.Number
}, {
decode: (i) =>
Effect.succeed({
myField: i.myField,
nextField: i.myField.length
}),
encode: (a) => Effect.succeed({ myField: a.myField })
}) {
nextMethod() {
return this.myMethod() + this.myField + this.nextField
}
}
Schema.Class<GitHubUser>('GitHubUser')({
id: Schema.Number,
html_url: Schema.String,
login: Schema.String,
avatar_url: Schema.String,
name: Schema.optional(Schema.String),
blog: Schema.optional(Schema.String),
email: Schema.optional(Schema.String),
}).transformOrFailFrom