@@ -13,7 +13,18 @@ interface UseSessionOptions {
1313 onUnauthenticated ?: ( ) => void
1414}
1515
16- type SignInOptions = Partial < UseSessionOptions >
16+ type GetSessionOptions = Partial < UseSessionOptions >
17+
18+ interface SignInOptions {
19+ /**
20+ * Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
21+ *
22+ * [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
23+ */
24+ callbackUrl ?: string
25+ /** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
26+ redirect ?: boolean
27+ }
1728
1829interface SignOutOptions {
1930 callbackUrl ?: string
@@ -57,12 +68,23 @@ export default async (initialGetSessionOptions: UseSessionOptions = {}) => {
5768 const data = useState < SessionData > ( 'session:data' , ( ) => undefined )
5869 const status = useState < SessionStatus > ( 'session:status' , ( ) => 'unauthenticated' )
5970
60- const signIn = ( ) => {
61- const url = joinPathToBase ( 'signin' )
62- window . location . href = url
71+ // TODO: Improve typing, make `provider` a literal union instead
72+ const signIn = async ( options ?: Pick < SignInOptions , 'callbackUrl' > ) => {
73+ const providers = await getProviders ( )
74+
75+ if ( ! providers ) {
76+ window . location . href = joinPathToBase ( 'error' )
77+ return
78+ }
79+
80+ const { callbackUrl = window . location . href } = options ?? { }
81+ window . location . href = `${ joinPathToBase ( 'signin' ) } ?${ new URLSearchParams ( {
82+ callbackUrl
83+ } ) } `
84+
85+ // TODO: Add support for credential and mail flows, see https://github.com/nextauthjs/next-auth/blob/733fd5f2345cbf7c123ba8175ea23506bcb5c453/packages/next-auth/src/react/index.tsx#L226-L228
6386 }
6487
65- // TODO: add callback url support https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/react/index.tsx#L284
6688 const signOut = async ( { callbackUrl } : SignOutOptions ) => {
6789 const csrfTokenResult = await getCsrfToken ( )
6890
@@ -98,7 +120,7 @@ export default async (initialGetSessionOptions: UseSessionOptions = {}) => {
98120
99121 const getCsrfToken = ( ) => _fetch < { csrfToken : string } > ( 'csrf' )
100122 const getProviders = ( ) => _fetch < AppProvider [ ] > ( 'providers' )
101- const getSession = ( getSessionOptions ?: SignInOptions ) => {
123+ const getSession = ( getSessionOptions ?: GetSessionOptions ) => {
102124 const { required, callbackUrl, onUnauthenticated } = defu ( getSessionOptions || { } , {
103125 required : true ,
104126 callbackUrl : undefined ,
0 commit comments