update demonstration code for better environment variable security

This commit is contained in:
Sean Mullen 2021-05-25 14:01:54 -04:00
parent b2d3995896
commit fd87866a51
6 changed files with 565 additions and 574 deletions

View File

@ -35,14 +35,14 @@ SvelteKitAuth is very easy to setup! All you need to do is instantiate the `Svel
export const appAuth = new SvelteKitAuth({ export const appAuth = new SvelteKitAuth({
providers: [ providers: [
new GoogleOAuthProvider({ new GoogleOAuthProvider({
clientId: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID, clientId: process.env['VITE_GOOGLE_OAUTH_CLIENT_ID'],
clientSecret: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_SECRET, clientSecret: process.env['GOOGLE_OAUTH_CLIENT_SECRET'],
profile(profile) { profile(profile) {
return { ...profile, provider: "google" }; return { ...profile, provider: "google" };
}, },
}), }),
], ],
jwtSecret: import.meta.env.JWT_SECRET_KEY, jwtSecret: process.env['JWT_SECRET_KEY'],
}); });
``` ```

View File

@ -33,6 +33,7 @@
"@fontsource/fira-mono": "^4.3.0", "@fontsource/fira-mono": "^4.3.0",
"@fontsource/inter": "^4.3.0", "@fontsource/inter": "^4.3.0",
"clsx": "^1.1.1", "clsx": "^1.1.1",
"dotenv": "^10.0.0",
"prismjs": "^1.23.0", "prismjs": "^1.23.0",
"sk-auth": "file:../" "sk-auth": "file:../"
} }

View File

@ -5,33 +5,36 @@ import {
RedditOAuth2Provider, RedditOAuth2Provider,
TwitterAuthProvider, TwitterAuthProvider,
} from "sk-auth/providers"; } from "sk-auth/providers";
import dotenv from 'dotenv';
dotenv.config();
export const appAuth = new SvelteKitAuth({ export const appAuth = new SvelteKitAuth({
providers: [ providers: [
new GoogleOAuth2Provider({ new GoogleOAuth2Provider({
clientId: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID, clientId: process.env['VITE_GOOGLE_OAUTH_CLIENT_ID'],
clientSecret: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_SECRET, clientSecret: process.env['GOOGLE_OAUTH_CLIENT_SECRET'],
profile(profile) { profile(profile) {
return { ...profile, provider: "google" }; return { ...profile, provider: "google" };
}, },
}), }),
new FacebookOAuth2Provider({ new FacebookOAuth2Provider({
clientId: import.meta.env.VITE_FACEBOOK_OAUTH_CLIENT_ID, clientId: process.env['VITE_FACEBOOK_OAUTH_CLIENT_ID'],
clientSecret: import.meta.env.VITE_FACEBOOK_OAUTH_CLIENT_SECRET, clientSecret: process.env['FACEBOOK_OAUTH_CLIENT_SECRET'],
profile(profile) { profile(profile) {
return { ...profile, provider: "facebook" }; return { ...profile, provider: "facebook" };
}, },
}), }),
new TwitterAuthProvider({ new TwitterAuthProvider({
apiKey: import.meta.env.VITE_TWITTER_API_KEY, apiKey: process.env['VITE_TWITTER_API_KEY'],
apiSecret: import.meta.env.VITE_TWITTER_API_SECRET, apiSecret: process.env['TWITTER_API_SECRET'],
profile(profile) { profile(profile) {
return { ...profile, provider: "twitter" }; return { ...profile, provider: "twitter" };
}, },
}), }),
new RedditOAuth2Provider({ new RedditOAuth2Provider({
apiKey: import.meta.env.VITE_REDDIT_API_KEY, apiKey: process.env['VITE_REDDIT_API_KEY'],
apiSecret: import.meta.env.VITE_REDDIT_API_SECRET, apiSecret: process.env['REDDIT_API_SECRET'],
profile(profile) { profile(profile) {
profile = RedditOAuth2Provider.profileHandler(profile); profile = RedditOAuth2Provider.profileHandler(profile);
return { ...profile, provider: "reddit" }; return { ...profile, provider: "reddit" };
@ -54,5 +57,5 @@ export const appAuth = new SvelteKitAuth({
return token; return token;
}, },
}, },
jwtSecret: import.meta.env.JWT_SECRET_KEY, jwtSecret: process.env['JWT_SECRET_KEY'],
}); });

View File

@ -14,8 +14,8 @@
const code = `export const appAuth = new SvelteKitAuth({ const code = `export const appAuth = new SvelteKitAuth({
providers: [ providers: [
new GoogleOAuthProvider({ new GoogleOAuthProvider({
clientId: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID, clientId: process.env['VITE_GOOGLE_OAUTH_CLIENT_ID'],
clientSecret: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_SECRET, clientSecret: process.env['GOOGLE_OAUTH_CLIENT_SECRET'],
profile(profile) { profile(profile) {
return { ...profile, provider: "google" }; return { ...profile, provider: "google" };
}, },
@ -37,7 +37,7 @@
return token; return token;
}, },
}, },
jwtSecret: import.meta.env.JWT_SECRET_KEY, jwtSecret: process.env['JWT_SECRET_KEY'],
});`; });`;
onMount(async () => { onMount(async () => {

File diff suppressed because it is too large Load Diff

416
yarn.lock

File diff suppressed because it is too large Load Diff