Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
supabase auth implementation w/ rough edges in UI/X
- Loading branch information
Showing
8 changed files
with
146 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,42 @@ | ||
import './session.js'; | ||
import './services/auth.js'; | ||
import { signIn, signOut, signUp, watchAuth } from './services/auth.js'; | ||
import { startSession } from './session.js'; | ||
|
||
const authSection = document.getElementById('auth-section'); | ||
const sessionSection = document.getElementById('session-section'); | ||
const hide = element => element.classList.add('hidden'); | ||
const show = element => element.classList.remove('hidden'); | ||
const authMode = () => { | ||
show(authSection); | ||
hide(sessionSection); | ||
hide(signOutButton); | ||
}; | ||
const sessionMode = () => { | ||
hide(authSection); | ||
show(sessionSection); | ||
show(signOutButton); | ||
}; | ||
|
||
const authForm = document.getElementById('auth-form'); | ||
const authError = document.getElementById('auth-error'); | ||
authForm.addEventListener('submit', async e => { | ||
e.preventDefault(); | ||
const action = e.submitter.name === 'sign-up' ? signUp : signIn; | ||
|
||
const formData = new FormData(authForm); | ||
const credentials = Object.fromEntries(formData.entries()); | ||
const { error } = await action(credentials); | ||
if (error) { | ||
authError.textContent = error?.message ?? error ?? 'Unexpected error'; | ||
} | ||
}); | ||
|
||
const signOutButton = document.getElementById('sign-out-button'); | ||
signOutButton.addEventListener('click', signOut); | ||
|
||
const startButton = document.getElementById('start-button'); | ||
startButton.addEventListener('click', startSession); | ||
|
||
watchAuth((_event, session) => { | ||
session ? sessionMode() : authMode(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm'; | ||
|
||
const SUPABASE_PROJECT_URL = 'http://localhost:54321'; | ||
const SUPABASE_API_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0'; | ||
|
||
export const client = createClient(SUPABASE_PROJECT_URL, SUPABASE_API_KEY); | ||
|
||
export function watchAuth(callback) { | ||
client.auth.onAuthStateChange(callback); | ||
} | ||
|
||
export async function signUp(credentials){ | ||
return await client.auth.signUp(credentials); | ||
} | ||
|
||
export async function signIn(credentials){ | ||
return await client.auth.signInWithPassword(credentials); | ||
} | ||
|
||
export async function signOut(){ | ||
return await client.auth.signOut(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters