mirror of
https://github.com/Dan6erbond/sk-auth.git
synced 2025-08-03 13:48:09 +02:00
✨ Add basic auth config to example app
This commit is contained in:
parent
768b7b9fef
commit
6da05b0542
15
example-app/src/hooks.ts
Normal file
15
example-app/src/hooks.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import type { Handle } from "@sveltejs/kit";
|
||||||
|
import { appAuth } from "$lib/appAuth";
|
||||||
|
|
||||||
|
export const handle: Handle = async ({ request, render }) => {
|
||||||
|
// TODO https://github.com/sveltejs/kit/issues/1046
|
||||||
|
if (request.query.has("_method")) {
|
||||||
|
request.method = request.query.get("_method").toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await render(request);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const { getSession } = appAuth;
|
101
example-app/src/lib/appAuth.ts
Normal file
101
example-app/src/lib/appAuth.ts
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import { Auth } from "svelte-kit-auth";
|
||||||
|
import {
|
||||||
|
FacebookAuthProvider,
|
||||||
|
GoogleOAuthProvider,
|
||||||
|
RedditOAuthProvider,
|
||||||
|
TwitterAuthProvider,
|
||||||
|
} from "svelte-kit-auth/providers";
|
||||||
|
|
||||||
|
export const appAuth = new Auth({
|
||||||
|
providers: [
|
||||||
|
new GoogleOAuthProvider({
|
||||||
|
clientId: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_ID,
|
||||||
|
clientSecret: import.meta.env.VITE_GOOGLE_OAUTH_CLIENT_SECRET,
|
||||||
|
profile(profile) {
|
||||||
|
return { ...profile, provider: "google" };
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new FacebookAuthProvider({
|
||||||
|
clientId: import.meta.env.VITE_FACEBOOK_OAUTH_CLIENT_ID,
|
||||||
|
clientSecret: import.meta.env.VITE_FACEBOOK_OAUTH_CLIENT_SECRET,
|
||||||
|
profile(profile) {
|
||||||
|
return { ...profile, provider: "facebook" };
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new TwitterAuthProvider({
|
||||||
|
apiKey: import.meta.env.VITE_TWITTER_API_KEY,
|
||||||
|
apiSecret: import.meta.env.VITE_TWITTER_API_SECRET,
|
||||||
|
profile(profile) {
|
||||||
|
return { ...profile, provider: "twitter" };
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new RedditOAuthProvider({
|
||||||
|
apiKey: import.meta.env.VITE_REDDIT_API_KEY,
|
||||||
|
apiSecret: import.meta.env.VITE_REDDIT_API_SECRET,
|
||||||
|
profile({
|
||||||
|
is_employee,
|
||||||
|
has_external_account,
|
||||||
|
snoovatar_img,
|
||||||
|
verified,
|
||||||
|
id,
|
||||||
|
over_18,
|
||||||
|
is_gold,
|
||||||
|
is_mod,
|
||||||
|
awarder_karma,
|
||||||
|
has_verified_email,
|
||||||
|
is_suspended,
|
||||||
|
icon_img,
|
||||||
|
pref_nightmode,
|
||||||
|
awardee_karma,
|
||||||
|
password_set,
|
||||||
|
link_karma,
|
||||||
|
total_karma,
|
||||||
|
name,
|
||||||
|
created,
|
||||||
|
created_utc,
|
||||||
|
comment_karma,
|
||||||
|
}) {
|
||||||
|
return {
|
||||||
|
is_employee,
|
||||||
|
has_external_account,
|
||||||
|
snoovatar_img,
|
||||||
|
verified,
|
||||||
|
id,
|
||||||
|
over_18,
|
||||||
|
is_gold,
|
||||||
|
is_mod,
|
||||||
|
awarder_karma,
|
||||||
|
has_verified_email,
|
||||||
|
is_suspended,
|
||||||
|
icon_img,
|
||||||
|
pref_nightmode,
|
||||||
|
awardee_karma,
|
||||||
|
password_set,
|
||||||
|
link_karma,
|
||||||
|
total_karma,
|
||||||
|
name,
|
||||||
|
created,
|
||||||
|
created_utc,
|
||||||
|
comment_karma,
|
||||||
|
provider: "reddit",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
callbacks: {
|
||||||
|
jwt(token, profile) {
|
||||||
|
if (profile?.provider) {
|
||||||
|
const { provider, ...account } = profile;
|
||||||
|
token = {
|
||||||
|
...token,
|
||||||
|
user: {
|
||||||
|
...token.user,
|
||||||
|
[provider]: account,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return token;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user