#1 adding auth
This commit is contained in:
@@ -2,13 +2,18 @@
|
||||
import '../app.css';
|
||||
import { onMount } from 'svelte';
|
||||
import type { Auth } from 'firebase/auth';
|
||||
import {
|
||||
getAuth,
|
||||
signInWithPopup,
|
||||
signInWithEmailAndPassword,
|
||||
EmailAuthProvider
|
||||
} from 'firebase/auth';
|
||||
|
||||
var auth: Auth;
|
||||
var auth: Auth | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
const firebaseApp = await import('firebase/app');
|
||||
const firebaseAuth = await import('firebase/auth');
|
||||
const firebaseUi = await import('firebaseui');
|
||||
|
||||
const app = firebaseApp.initializeApp({
|
||||
apiKey: 'AIzaSyCrJBW3c3Wut8DqjyVJoFAEyJ9Had__q-Q',
|
||||
authDomain: 'me-fit-a9365.firebaseapp.com',
|
||||
@@ -18,22 +23,37 @@
|
||||
appId: '1:631045688520:web:c7e0534927b52b0db629fd'
|
||||
});
|
||||
|
||||
auth = firebaseAuth.getAuth(app);
|
||||
|
||||
var ui = new firebaseUi.auth.AuthUI(auth);
|
||||
ui.start('#firebaseui-auth-container', {
|
||||
signInOptions: [
|
||||
{ provider: firebaseAuth.EmailAuthProvider.PROVIDER_ID, requireDisplayName: false }
|
||||
]
|
||||
|
||||
// Other config options...
|
||||
});
|
||||
auth = getAuth(app);
|
||||
});
|
||||
|
||||
const signIn = async () => {
|
||||
try {
|
||||
const provider = new EmailAuthProvider();
|
||||
const result = await signInWithEmailAndPassword(auth as Auth, google);
|
||||
console.log(result);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const signOut = async () => {
|
||||
try {
|
||||
await (auth as Auth).signOut();
|
||||
console.log('Signed out');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
$: user = (auth as any as Auth)?.currentUser;
|
||||
</script>
|
||||
|
||||
<p class="text-9xl text-red-950">Tailwind working</p>
|
||||
|
||||
<div id="firebaseui-auth-container"></div>
|
||||
<button on:click={async () => console.log(await auth.currentUser?.getIdToken())}>Click me</button>
|
||||
<button on:click={async () => signIn()}>Login</button>
|
||||
<button on:click={async () => signOut()}>Logout</button>
|
||||
<!-- <button on:click={async () => console.log(await (auth as Auth).currentUser?.getIdToken())}>Click me</button> -->
|
||||
|
||||
<p>{user?.email}</p>
|
||||
|
||||
<slot></slot>
|
||||
|
||||
1
view/src/routes/login/+page.svelte
Normal file
1
view/src/routes/login/+page.svelte
Normal file
@@ -0,0 +1 @@
|
||||
<h2>Login</h2>
|
||||
Reference in New Issue
Block a user