-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
161 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@solid-mediakit/auth': patch | ||
--- | ||
|
||
feat: auth.refetch function |
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
4 changes: 2 additions & 2 deletions
4
examples/auth/src/server/middleware.ts → examples/auth/src/middleware.ts
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,7 +1,7 @@ | ||
import { authMiddleware } from '@solid-mediakit/auth' | ||
import { createMiddleware } from '@solidjs/start/middleware' | ||
import { authOptions } from './auth' | ||
import { authOptions } from './server/auth' | ||
|
||
export default createMiddleware({ | ||
onRequest: [], | ||
onRequest: [authMiddleware(true, authOptions)], | ||
}) |
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,30 @@ | ||
import { useAuth } from '@solid-mediakit/auth/client' | ||
import { useParams } from '@solidjs/router' | ||
import { createEffect, on, VoidComponent } from 'solid-js' | ||
|
||
const AuthProvider: VoidComponent = () => { | ||
const params = useParams() | ||
const auth = useAuth() | ||
createEffect( | ||
on(auth.status, (status) => { | ||
if (status === 'authenticated') { | ||
window.close() | ||
} else if (status === 'unauthenticated') { | ||
void auth.signIn(params.provider) | ||
} | ||
}), | ||
) | ||
|
||
return ( | ||
<div class='h-full w-full flex items-center justify-center flex-col gap-4'> | ||
<div class='text-white text-2xl font-bold animate-pulse'> | ||
Redirecting... | ||
</div> | ||
<p class='text-offwhite text-lg font-medium'> | ||
Please Wait While HackChat Is Validating Your Request | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default AuthProvider |
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,67 @@ | ||
import { Component, createEffect, VoidComponent } from 'solid-js' | ||
import { AiFillGithub } from 'solid-icons/ai' | ||
import { FaBrandsDiscord } from 'solid-icons/fa' | ||
import { A } from '@solidjs/router' | ||
import { capitalize } from '~/utils/string' | ||
import { getSession, useAuth } from '@solid-mediakit/auth/client' | ||
const Auth: VoidComponent = () => { | ||
return ( | ||
<div class='flex flex-col gap-4 items-center h-full w-full'> | ||
<h1 class='text-3xl font-bold text-offwhite'> | ||
Log In To{' '} | ||
<span class='decoration-offwhite underline decoration-dotted text-white'> | ||
HackChat | ||
</span> | ||
</h1> | ||
<div class='flex flex-col gap-3 w-[300px] items-center'> | ||
<SignInMethod name='github' /> | ||
<SignInMethod name='discord' /> | ||
<div class='my-3 w-[80%] rounded-lg bg-gray-200 h-[0.5px]' /> | ||
<p class='text-gray-300 font-semibold text-sm w-full text-center'> | ||
For privacy of the users, you are required to Sign In before sending | ||
any messages. | ||
</p> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Auth | ||
|
||
const SignInMethod: Component<{ name: 'github' | 'discord' }> = (props) => { | ||
const auth = useAuth() | ||
return ( | ||
<button | ||
style={{ | ||
'box-shadow': `0 0 0 1px ${ | ||
props.name === 'github' ? '#24292e' : '#5865F2' | ||
}`, | ||
}} | ||
class={`flex gap-2 items-center w-full justify-center transition-all select-none ${ | ||
props.name === 'github' | ||
? 'bg-[#24292e] hover:bg-[#555] hover:shadow-[#555]' | ||
: 'hover:shadow-[#5865F2] bg-[#5865F2] hover:bg-opacity-80' | ||
} text-white px-[14px] h-12 rounded-lg font-medium`} | ||
onClick={() => { | ||
const w = window.open( | ||
`${window.location.origin}/auth/${props.name}`, | ||
`Sign In With ${capitalize(props.name)}`, | ||
) | ||
setInterval(async () => { | ||
console.log( | ||
w?.closed, | ||
auth.session(), | ||
w?.closed && (await auth.refetch(true)), | ||
) | ||
}, 1000) | ||
}} | ||
> | ||
{props.name === 'github' ? ( | ||
<AiFillGithub size={25} /> | ||
) : ( | ||
<FaBrandsDiscord size={25} /> | ||
)} | ||
Continue With {capitalize(props.name)} | ||
</button> | ||
) | ||
} |
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,2 @@ | ||
export const capitalize = (str: string) => | ||
`${str.slice(0, 1).toUpperCase()}${str.slice(1)}`; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.