-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor folder structure to fix extracted serverfns
- Loading branch information
1 parent
6deb70b
commit 083cee7
Showing
8 changed files
with
90 additions
and
142 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {action, cache, redirect} from '@solidjs/router'; | ||
import {OAuthProvider} from 'node-appwrite'; | ||
import {getHeaders} from 'vinxi/http'; | ||
import {createAdminClient} from './server/appwrite'; | ||
import {getLoggedInUser, getSession, logoutSession} from './server/session'; | ||
|
||
export const loggedInUser = cache(async () => { | ||
'use server'; | ||
const session = await getSession(); | ||
const userId = session.data.session?.userId; | ||
if (!userId) return null; | ||
return getLoggedInUser(); | ||
}, 'currentUser'); | ||
|
||
export const signupWithGithub = action(async () => { | ||
'use server'; | ||
const {account} = await createAdminClient(); | ||
|
||
const origin = getHeaders().origin; | ||
const successUrl = `${origin}/api/oauth`; | ||
const failureUrl = `${origin}/`; | ||
|
||
try { | ||
const redirectUrl = await account.createOAuth2Token( | ||
OAuthProvider.Github, | ||
successUrl, | ||
failureUrl, | ||
); | ||
return redirect(redirectUrl); | ||
} catch (e) { | ||
console.error(e); | ||
return redirect('error'); | ||
} | ||
}, 'signup-with-github'); | ||
|
||
export const logout = action(async () => { | ||
'use server'; | ||
await logoutSession(); | ||
return redirect('/'); | ||
}, 'logout'); |
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