mirror of
https://github.com/Dan6erbond/sk-auth.git
synced 2025-07-30 13:46:20 +02:00
🎨 Enable TS strict
mode and set target to es2017
This commit is contained in:
parent
7a9a9c48c9
commit
bd4ae4387e
@ -12,6 +12,7 @@ module.exports = {
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["off", { argsIgnorePattern: "^_" }],
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
|
12
src/auth.ts
12
src/auth.ts
@ -115,8 +115,7 @@ export class Auth {
|
||||
}
|
||||
|
||||
const jwt = this.signToken(token);
|
||||
console.log(jwt);
|
||||
const redirect = await this.getRedirectUrl(host, redirectUrl);
|
||||
const redirect = await this.getRedirectUrl(host, redirectUrl ?? undefined);
|
||||
|
||||
return {
|
||||
status: 302,
|
||||
@ -158,9 +157,9 @@ export class Auth {
|
||||
|
||||
const match = path.match(/\/api\/auth\/(?<method>signin|callback)\/(?<provider>\w+)/);
|
||||
|
||||
if (match) {
|
||||
if (match && match.groups) {
|
||||
const provider = this.config?.providers?.find(
|
||||
(provider) => provider.id === match.groups.provider,
|
||||
(provider) => provider.id === match.groups!.provider,
|
||||
);
|
||||
if (provider) {
|
||||
if (match.groups.method === "signin") {
|
||||
@ -170,6 +169,11 @@ export class Auth {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
status: 404,
|
||||
body: "Not found.",
|
||||
};
|
||||
}
|
||||
|
||||
get: RequestHandler = async (request) => {
|
||||
|
@ -19,17 +19,19 @@ export async function signIn(provider: string, data?: any, config?: SignInConfig
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
let redirectUrl: string;
|
||||
let redirectUrl: string | undefined;
|
||||
if (config?.redirectUrl) {
|
||||
redirectUrl = config.redirectUrl;
|
||||
} else {
|
||||
let $val: Page;
|
||||
let $val: Page | undefined;
|
||||
page.subscribe(($) => ($val = $))();
|
||||
redirectUrl = `${$val.host}${$val.path}?${$val.query}`;
|
||||
if ($val) {
|
||||
redirectUrl = `${$val.host}${$val.path}?${$val.query}`;
|
||||
}
|
||||
}
|
||||
|
||||
const queryData = {
|
||||
redirect: redirectUrl,
|
||||
redirect: redirectUrl ?? "/",
|
||||
};
|
||||
const query = new URLSearchParams(queryData);
|
||||
const path = `/api/auth/login/${provider}?${query}`;
|
||||
|
@ -11,7 +11,7 @@ export abstract class Provider<T extends ProviderConfig = ProviderConfig> {
|
||||
id: string;
|
||||
|
||||
constructor(protected readonly config: T) {
|
||||
this.id = config.id;
|
||||
this.id = config.id!;
|
||||
}
|
||||
|
||||
getUri(host: string, path: string) {
|
||||
|
@ -28,7 +28,7 @@ export class FacebookAuthProvider extends OAuth2Provider<FacebookAuthProviderCon
|
||||
|
||||
const data = {
|
||||
client_id: this.config.clientId,
|
||||
scope: this.config.scope,
|
||||
scope: this.config.scope!,
|
||||
redirect_uri: this.getCallbackUri(host),
|
||||
state,
|
||||
};
|
||||
@ -69,7 +69,7 @@ export class FacebookAuthProvider extends OAuth2Provider<FacebookAuthProviderCon
|
||||
|
||||
const data = {
|
||||
access_token: tokens.access_token,
|
||||
fields: this.config.userProfileFields,
|
||||
fields: this.config.userProfileFields!,
|
||||
};
|
||||
|
||||
const res = await fetch(`${endpoint}?${new URLSearchParams(data)}`);
|
||||
|
@ -23,7 +23,7 @@ export class GoogleOAuthProvider extends OAuth2Provider<GoogleOAuthProviderConfi
|
||||
}
|
||||
|
||||
async getProviderMetadata() {
|
||||
const res = await fetch(this.config.discoveryDocument);
|
||||
const res = await fetch(this.config.discoveryDocument!);
|
||||
const metadata = await res.json();
|
||||
return metadata;
|
||||
}
|
||||
@ -39,7 +39,7 @@ export class GoogleOAuthProvider extends OAuth2Provider<GoogleOAuthProviderConfi
|
||||
const data = {
|
||||
response_type: "code",
|
||||
client_id: this.config.clientId,
|
||||
scope: this.config.scope,
|
||||
scope: this.config.scope!,
|
||||
redirect_uri: this.getCallbackUri(host),
|
||||
state,
|
||||
login_hint: "example@provider.com",
|
||||
|
@ -35,7 +35,7 @@ export abstract class OAuth2Provider<T extends OAuth2ProviderConfig> extends Pro
|
||||
|
||||
getStateValue(query: URLSearchParams, name: string) {
|
||||
if (query.get("state")) {
|
||||
const state = Buffer.from(query.get("state"), "base64").toString();
|
||||
const state = Buffer.from(query.get("state")!, "base64").toString();
|
||||
return state
|
||||
.split(",")
|
||||
.find((state) => state.startsWith(`${name}=`))
|
||||
@ -47,7 +47,7 @@ export abstract class OAuth2Provider<T extends OAuth2ProviderConfig> extends Pro
|
||||
const code = query.get("code");
|
||||
const redirect = this.getStateValue(query, "redirect");
|
||||
|
||||
const tokens = await this.getTokens(code, this.getCallbackUri(host));
|
||||
const tokens = await this.getTokens(code!, this.getCallbackUri(host));
|
||||
let user = await this.getUserProfile(tokens);
|
||||
|
||||
if (this.config.profile) {
|
||||
|
@ -79,8 +79,8 @@ export class RedditOAuthProvider extends OAuth2Provider<RedditOAuthProviderConfi
|
||||
response_type: "code",
|
||||
state,
|
||||
redirect_uri: this.getCallbackUri(host),
|
||||
duration: this.config.duration,
|
||||
scope: this.config.scope,
|
||||
duration: this.config.duration!,
|
||||
scope: this.config.scope!,
|
||||
};
|
||||
|
||||
const url = `${endpoint}?${new URLSearchParams(data)}`;
|
||||
|
@ -75,7 +75,7 @@ export class TwitterAuthProvider extends OAuth2Provider<TwitterAuthProviderConfi
|
||||
const oauthVerifier = query.get("oauth_verifier");
|
||||
const redirect = this.getStateValue(query, "redirect");
|
||||
|
||||
const tokens = await this.getTokens(oauthToken, oauthVerifier);
|
||||
const tokens = await this.getTokens(oauthToken!, oauthVerifier!);
|
||||
let user = await this.getUserProfile(tokens);
|
||||
|
||||
if (this.config.profile) {
|
||||
|
@ -1,14 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"target": "es2017",
|
||||
"module": "es6",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
|
Loading…
Reference in New Issue
Block a user